<el-col :span="12" v-for="(item,index) in Unitchartslist" :key="index">
<div>{{item.chartTitle}}</div>
<div class="roseChart" style="width: 100%; height: 300px;"></div>
</el-col>
drawunitline(bluename,greenname,yellowname,redname){
var echarts = require("echarts");
var roseCharts = document.getElementsByClassName('roseChart'); // 对应地使用ByClassName
for(var i = 0;i < roseCharts.length;i++ ){ // 通过for循环,在相同class的dom内绘制元素
var myChart = echarts.init(roseCharts[i]);
myChart.setOption({
legend: {
},
tooltip: {
trigger: "axis",
},
grid: {
},
xAxis: [{
type: "category",
boundaryGap: false,
axisLabel: {
formatter: '{value}',
textStyle: {
color: "#333"
}
},
axisLine: {
lineStyle: {
color: "#D9D9D9"
}
},
data: this.Unitchartslist[i].xaxis
}],
yAxis: [{
type: 'value',
axisTick: {
show: false
},
axisLine: {
show: true,
lineStyle: {
color: '#DCE2E8'
}
},
axisLabel: {
textStyle: {
color: '#556677'
}
},
splitLine: {
lineStyle: { color: "#E5E5E5",}
},
splitLine: {
show: false
}
}, {
type: 'value',
position: 'right',
name: '百分比',
axisTick: {
show: false
},
axisLabel: {
textStyle: {
color: '#556677'
},
formatter: '{value}'
},
axisLine: {
show: true,
lineStyle: {
color: '#556677'
}
},
splitLine: {
show: false
}
}],
series: [{
name:bluename,
type: 'line',
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(35, 87, 224,0.3)'
},
{
offset: 1,
color: 'rgba(35, 87, 224,0)'
}
], false),
shadowColor: 'rgba(35, 87, 224, 0.9)',
shadowBlur: 20
}
},
data:this.Unitchartslist[i].bluedata,
symbolSize: 1,
symbol: 'circle',
smooth: true,
yAxisIndex: 0,
showSymbol: false,
itemStyle: {
normal: {
color: '#1C70DD',
borderColor: '#1C70DD'
}
}
},
{
name:redname,
type: 'line',
data:this.Unitchartslist[i].reddata,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(217, 31, 35,0.3)'
},
{
offset: 1,
color: 'rgba(217, 31, 35,0)'
}
], false),
shadowColor: 'rgba(217, 31, 35, 0.9)',
shadowBlur: 20
}
},
symbolSize: 1,
symbol: 'circle',
smooth: true,
yAxisIndex: 0,
showSymbol: false,
itemStyle: {
normal: {
color: '#D91F23',
borderColor: '#D91F23'
}
}
},
, {
name:yellowname,
type: 'line',
data:this.Unitchartslist[i].yellowdata,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(255, 170,1,0.3)'
},
{
offset: 1,
color: 'rgba(255, 170,1,0)'
}
], false),
shadowColor: 'rgba(255, 170,1, 0.9)',
shadowBlur: 20
}
},
symbolSize: 1,
symbol: 'circle',
smooth: true,
yAxisIndex: 0,
showSymbol: false,
itemStyle: {
normal: {
color: '#FFAA01',
borderColor:' #FFAA01'
}
}
},
{
name:greenname,
type: 'line',
data:this.Unitchartslist[i].greendata,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(1, 254, 210,0.3)'
},
{
offset: 1,
color: 'rgba(1, 254, 210,0)'
}
], false),
shadowColor: 'rgba(1, 254, 210, 0.9)',
shadowBlur: 20
}
},
symbolSize: 1,
yAxisIndex: 1,
symbol: 'circle',
smooth: true,
showSymbol: false,
itemStyle: {
normal: {
color: '#01FED2',
borderColor: '#01FED2'
}
}
}
]
},true)
}
},
处理后台数据
getunitConsumption(){
let data={
beginDate:this.beginDate,
endDate:this.endDate,
timePeriod:this.timePeriod,
type:1
}
unitConsumption(data).then((response) => {
this.dataunitList=response.data.dataList
this.tableunitColumnList=response.data.tableColumnList
this.Unitchartslist=response.data.multipleLineChartVOs
for (let k = 0; k < this.Unitchartslist.length; k++) {
for (let i = 0; i < this.Unitchartslist[k].yaxis.length; i++) {
if(this.Unitchartslist[k].yaxis[i].name=='单位产量'){
this.Unitchartslist[k].bluedata=this.Unitchartslist[k].yaxis[i].data
}else if(this.Unitchartslist[k].yaxis[i].name=='环比'){
this.Unitchartslist[k].greendata=this.Unitchartslist[k].yaxis[i].data
}else if(this.Unitchartslist[k].yaxis[i].name=='同比'){
this.Unitchartslist[k].yellowdata=this.Unitchartslist[k].yaxis[i].data
}else if(this.Unitchartslist[k].yaxis[i].name=='平均值'){
this.Unitchartslist[k].reddata=this.Unitchartslist[k].yaxis[i].data
}
}
}
// console.log("this.Unitchartslist",this.Unitchartslist)
this.$nextTick(()=> {
this.bluename='单位产量'
this.greenname='环比'
this.yellowname='同比'
this.redname='平均值'
this.drawunitline(this.bluename,this.greenname,this.yellowname,this.redname)
})
})
},