遍历双y轴折线图

在这里插入图片描述

<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)
                    })
                })
            },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值