<div id="lineEchart"></div>
getLineChart(){
let mychart=this.$echarts.init(document.getElementById('lineEchart'))
let seriesList=[],lengedList=[]
let data={
xdata:['20200301','20200302','20200303','20200304','20200305','20200306','20200307'],
seriesData:[
{name:'组合1',data:[20,30,21,22,25,32,30]},
{name:'组合2',data:[24,34,44,40,36,35,29]},
{name:'组合3',data:[50,52,41,48,37,40,45]},
{name:'组合4',data:[36,34,30,24,28,39,38]},
{name:'组合5',data:[46,42,37,46,41,40,35]}
]
}
let colors = ['235,100,148', '20,224,219','25,150,237','248,246,103']
let colors2 =['#eb6494','#14e0db','#1996ed','#f8f667']
let i=0;
data.seriesData.forEach(item=>{
let color = colors[i%colors.length];
let obj={
name: item.name,
type: 'line',
yAxisIndex: 0,
data:item.data,
color: colors2[i],
showSymbol:false,
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: 'rgba('+color+',0.9)'
}, {
offset: 1,
color: '#fff'
} ],
global: false // 缺省为 false
},
},
}
seriesList.push(obj)
lengedList.push(item.name)
i++
})
const option = {
tooltip: {
trigger: 'axis',
},
legend:{
bottom:'1%',
data:lengedList
},
grid: {
top:'8%',
left: '3%',
right: '4%',
bottom: '20%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: data.xdata,
axisLabel: {
// rotate: 60, x轴文字旋转
formatter(val) {
if (val === 'undefined' || val === 'null') return '';
return val
},
}
},
yAxis: [
{
type: 'value',
scale:true, //不强制包含0刻度
axisLabel: {
formatter: function (value) {
return value
}
}
},
],
series:seriesList,
};
mychart.setOption(option);
},