遍历多个多Y轴折线图

<el-row :gutter="20">
     <el-col :span="8" v-for="item in orderlist" :key="item.id">
         <div>零件号:{{item.lingjianhao}}</div>
         <div>模具编号:{{item.muju}}</div>
         <div>模型架号:{{item.muxing}}</div>
         <div>浇注开始:{{item.kaishi}}</div>
         <div>浇注结束:{{item.jieshu}}</div>
         <div class="chartsheight orderChart" ></div>
     </el-col>
 </el-row>
// 遍历出多Y 轴折线图
        draworderline(){
            var echarts = require("echarts");
            var colors = ['#5793f3', '#d14a61', '#675bba'];
            var orderChart = document.getElementsByClassName('orderChart'); // 对应地使用ByClassName
            for(var i = 0;i < orderChart.length;i++ ){ // 通过for循环,在相同class的dom内绘制元素
                var myChart = echarts.init(orderChart[i]);
                let Ydata=[];
                // 遍历多Y轴
                for (let n = 0, l = this.orderlist[i].legenddata.length; n < l; n++) {
                    Ydata.push({
                        type: 'value',
                        name: this.orderlist[i].legenddata[n],
                        axisLine: {
                            lineStyle: {
                                color: colors[n]
                            }
                        },
                        offset: (Ydata.length + 1) <= 2 ? 0 : (Math.ceil((Ydata.length + 1) / 2) - 1) * 40,
                        axisLabel: {
                            formatter: function(value) {
                                return value 
                            }
                            // formatter: '{value} ml'
                        }
                    })
                }
                myChart.setOption({
                    color: colors,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {type: 'cross'}
                    },
                    grid: {
                        right: '20%'
                    },
                    legend: {
                        data: this.orderlist[i].legenddata,
                        // data:['蒸发量','降水量','平均温度']
                    },
                    xAxis: [
                        {
                            type: 'category',
                            axisTick: {
                                alignWithLabel: true
                            },
                            data: this.orderlist[i].xAxisdata,
                            // data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
                        }
                    ],
                    yAxis: Ydata,
                    // yAxis: [
                        // {
                        //     type: 'value',
                        //     name: '蒸发量',
                        //     axisLine: {
                        //         lineStyle: {
                        //             color: colors[0]
                        //         }
                        //     },
                        //     axisLabel: {
                        //         formatter: '{value} ml'
                        //     }
                        // },
                        // {
                        //     type: 'value',
                        //     name: '降水量',
                        //     offset: 60,
                        //     axisLine: {
                        //         lineStyle: {
                        //             color: colors[1]
                        //         }
                        //     },
                        //     axisLabel: {
                        //         formatter: '{value} ml'
                        //     }
                        // },
                        // {
                        //     type: 'value',
                        //     name: '平均温度',
                        //     axisLine: {
                        //         lineStyle: {
                        //             color: colors[2]
                        //         }
                        //     },
                        //     axisLabel: {
                        //         formatter: '{value} °C'
                        //     }
                        // }
                    // ],
                    series:this.orderlist[i].yAxisdata,
                    // series: [
                    //     {
                    //         name:'蒸发量',
                    //         type:'line',
                    //         data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                    //     },
                    //     {
                    //         name:'降水量',
                    //         type:'line',
                    //         yAxisIndex: 1,
                    //         data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
                    //     },
                    //     {
                    //         name:'平均温度',
                    //         type:'line',
                    //         yAxisIndex: 2,
                    //         data:[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                    //     }
                    // ]


                },true)
            }
        },
// 顺序折线图
        orderlist:[
            {
                lingjianhao:'奔驰左前座椅',
                muju:'BZQ1',
                muxing:'89',
                kaishi:'2023-07-17 22:03:50.000',
                jieshu:'2023-07-20 22:03:50.000',
                legenddata:['蒸发量','降水量','平均温度'],
                xAxisdata: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                yAxisdata:[
                    {
                        name:'蒸发量',
                        type:'line',
                        yAxisIndex: 0,
                        data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                    },
                    {
                        name:'降水量',
                        type:'line',
                        yAxisIndex: 1,
                        data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
                    },
                    {
                        name:'平均温度',
                        type:'line',
                        yAxisIndex: 2,
                        data:[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                    }
                ]
            },
            {
                lingjianhao:'奔驰左前座椅',
                muju:'BZQ1',
                muxing:'89',
                kaishi:'2023-07-17 22:03:50.000',
                jieshu:'2023-07-20 22:03:50.000',
                legenddata:['温度','湿度','速度'],
                xAxisdata: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                yAxisdata:[
                    {
                        name:'温度',
                        type:'line',
                        yAxisIndex: 0,
                        data:[122.0, 4.9, 7.0, 23.2, 25.6, 76.7, 35.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                    },
                    {
                        name:'湿度',
                        type:'line',
                        yAxisIndex: 1,
                        data:[102.6, 5.9, 9.0, 26.4, 28.7, 70.7, 75.6, 182.2, 48.7, 18.8, 6.0, 2.3]
                    },
                    {
                        name:'速度',
                        type:'line',
                        yAxisIndex: 2,
                        data:[200.0, 2.2, 3.3, 4.5, 6.3, 10.2, 120.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                    }
                ]
            },
            {
                lingjianhao:'奔驰左前座椅',
                muju:'BZQ1',
                muxing:'89',
                kaishi:'2023-07-17 22:03:50.000',
                jieshu:'2023-07-20 22:03:50.000',
                legenddata:['电流','电压','压力'],
                xAxisdata: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                yAxisdata:[
                    {
                        name:'电流',
                        type:'line',
                        yAxisIndex: 0,
                        data:[2.0, 4.9, 7.0, 123.2, 25.6, 76.7, 135.6, 162.2, 32.6, 120.0, 60.4, 3.3]
                    },
                    {
                        name:'电压',
                        type:'line',
                        yAxisIndex: 1,
                        data:[2.6, 5.9, 9.0, 426.4, 238.7, 70.7, 175.6, 182.2, 48.7, 88.8, 6.0, 2.3]
                    },
                    {
                        name:'压力',
                        type:'line',
                        yAxisIndex: 2,
                        data:[2.0, 290.2, 3.3, 4.5, 6.3, 240.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                    }
                ]
            },
### 回答1: 你可以使用 Matplotlib 库来批量画出很多折线图。你可以使用循环来遍历数据集,并使用 Matplotlib 的 plot() 函数来绘制每个数据集的折线图。以下是一个示例代码: ```python import matplotlib.pyplot as plt # 数据集 data = [[1, 2, 3], [2, 4, 6], [3, 6, 9], [4, 8, 12]] # 循环遍历数据集并绘制折线图 for i in range(len(data)): plt.plot(data[i]) # 显示图形 plt.show() ``` 这段代码将绘制四个折线图,每个折线图都是由一个数据集绘制而成。你可以根据需要修改数据集和循环来绘制更多的折线图。 ### 回答2: 在使用Python批量绘制很多折线图时,可以使用循环结构和适当的数据集合。 首先,需要准备相关的数据集合。可以将需要绘制的折线图的数据存储在一个列表或者一个多维数组中,每个元素都代表一个折线图的数据。例如: data = [ [x1_values, y1_values], [x2_values, y2_values], ... ] 其中,x1_values和y1_values分别代表第一个折线图的横坐标和纵坐标数据,以此类推。 然后,可以使用循环结构遍历数据集合,并利用Matplotlib库来绘制折线图。具体步骤如下: 1. 导入Matplotlib库: ```python import matplotlib.pyplot as plt ``` 2. 遍历数据集合,并绘制每个折线图: ```python for i in range(len(data)): plt.plot(data[i][0], data[i][1]) ``` 其中,`data[i][0]`表示第i个数据对应的横坐标,`data[i][1]`表示第i个数据对应的纵坐标。 3. 可选地,可以添加标题、坐标轴标签等。 4. 可选地,可以保存绘制的折线图到文件中: ```python plt.savefig("path/to/save/figure.png") ``` 最后,调用`plt.show()`显示绘制的折线图。 这样,就可以使用Python批量绘制很多折线图了。需注意根据实际需求调整数据集合的形式,以及绘制其他风格和属性的折线图。 ### 回答3: 在Python中,可以使用matplotlib库来绘制折线图,并通过循环和列表等方法批量绘制很多折线图。 首先,你需要安装matplotlib库,可以使用pip命令在终端中安装:pip install matplotlib。 接下来,导入matplotlib库中的pyplot模块,一般以plt作为别名:import matplotlib.pyplot as plt。 然后,准备好需要绘制的数据集:可以将数据集存储在一个列表或者是一个嵌套列表中。每个列表中的元素代表一个折线图的数据点。也可以选择存储在一个字典或者是一个嵌套字典中,键为折线图的标签,值为对应的数据列表。 接下来,使用for循环遍历数据集,每次遍历取出一个数据集。 在for循环中,首先可以选择设置绘图窗口的大小plt.figure(figsize=(宽度, 高度))。 然后,使用plt.plot()函数来绘制折线图,传入数据集,可以传入参数来设置折线图的颜色、线型、标签等信息。 继续在for循环中,可以选择设置横坐标和纵坐标的标签plt.xlabel()和plt.ylabel(),设置折线图的标题plt.title(),设置图例plt.legend()等。 最后,使用plt.show()函数来显示绘制完成的折线图。 以下是一个简单示例代码,用于批量绘制多个折线图: ```python import matplotlib.pyplot as plt # 准备需要绘制的数据集 data_set = [[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20]] # 遍历数据集并绘制折线图 for data in data_set: # 设置绘图窗口的大小 plt.figure(figsize=(6, 4)) # 绘制折线图 plt.plot(data, label='Line') # 设置横坐标和纵坐标的标签 plt.xlabel('X-axis') plt.ylabel('Y-axis') # 设置折线图的标题 plt.title('Line Chart') # 设置图例 plt.legend() # 显示绘制完成的折线图 plt.show() ``` 运行以上代码,就可以批量绘制多个折线图。每个折线图对应一个数据集,可以根据具体需求更改数据集的内容、折线图的样式等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值