【echarts】柱图+折线图

// 数据项
powerUse: {
    realTime: [1, 2, 4, 6],
    history: [9, 9, 3, 4],
    dataX: ['2时', '4时', '6时']
}
drawChart2() {
    let myChartContainer4 = document.getElementById("chartContainer2");
    if (myChartContainer4) {
        this.echart2 = this.$echart.init(myChartContainer4);
        let e2Data = this.powerUse;
        // e2Data.dataX = this.get24Hour();

        let points = [];// 描点路径(转换数据)
        let hightLine = [];
        if (e2Data.realTime.length) {
            e2Data.realTime.forEach(function (value, index) {
                points.push([index, value]);
            });
            hightLine = [{ coords: points }];
        } else {
            hightLine = [];
        }

        this.echart2.setOption({
            tooltip: {
                trigger: "axis",
            },
            legend: {
                data: [
                    {
                        name: "实时负荷",
                        icon: "line"
                    },
                    {
                        name: "历史均值",
                        icon: "rect"
                    }
                ],
                itemHeight: 8,
                itemWidth: 15,
                top: 0,
                right: "2%",
                textStyle: {
                    color: "#1E3765"
                }
            },
            grid: {
                left: "3%",
                right: "3%",
                bottom: 5,
                top: 30,
                containLabel: true
            },
            toolbox: {
                show: false
            },
            xAxis: {
                type: "category",
                // boundaryGap: true, //X轴不从零开始
                axisTick: {
                    show: false
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: "#2C89AD" //轴线的颜色
                    }
                },
                axisLabel: {
                    color: "#1E3765"
                },
                data: e2Data.dataX,
            },
            yAxis: {
                name: "单位/kW·h",
                nameGap: 10,
                nameTextStyle: {
                    color: "#4473A4",
                    padding: [3, 4, 5, 20]
                },
                type: "value",
                axisTick: {
                    show: false
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: ["#2C89AD"], //网格线的颜色
                        type: "dashed",
                        width: 0.5
                    }
                },
                axisLine: {
                    show: "true",
                    lineStyle: {
                        color: "#00A8DD" //Y轴的颜色
                    }
                },
                axisLabel: {
                    color: "#4473A4"
                }
            },
            series: [
                {
                    name: "历史均值",
                    type: "bar",
                    barWidth: 15,
                    itemStyle: {
                        color: new this.$echart.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                { offset: 0, color: "#4BDDBB" },
                                { offset: 1, color: "#3DA4FF" }
                            ], false
                        ),
                        barBorderRadius: [0, 0, 5, 5],
                        label: {
                            show: false,
                            position: "top"
                        }
                    },
                    data: e2Data.history
                },
                {
                    name: "历史均值",// top
                    type: "pictorialBar",
                    tooltip: { show: false },
                    symbolSize: [15, 10],
                    symbolOffset: [0, -5],
                    symbolPosition: "end",
                    color: "#4BDDBB",
                    z: 12,
                    data: e2Data.history
                },
                {
                    name: "实时负荷",
                    type: "line",
                    z: 14,
                    areaStyle: {
                        color: new this.$echart.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                { offset: 0, color: "rgba(255,155,0, 0.3)" },
                                { offset: 1, color: "rgba(255,155,0, 0)" }
                            ], false
                        ),
                        shadowColor: "rgba(0, 0, 0, 0.1)",
                        shadowBlur: 5
                    },
                    itemStyle: {
                        color: "rgb(255,155,0)",
                        borderColor: "rgba(255,155,0,0.2)",
                        borderWidth: 6
                    },
                    data: e2Data.realTime
                },
                {
                    coordinateSystem: "cartesian2d",
                    name: "实时负荷",
                    type: "lines",
                    zlevel: 2,
                    polyline: true,
                    effect: {
                        show: true,
                        period: 15,
                        trailLength: 0.5, // 线的小尾巴
                        symbolSize: 5,
                        color: "#fff",
                        loop: true
                    },
                    lineStyle: {
                        width: 0.01
                    },
                    silent: true,
                    data: hightLine
                }
            ]
        });
    }
},

在这里插入图片描述

ECharts是一款开源的数据可视化库,可以用于创建各种类型的表,包括折线图用于显示不同类别或组的数据之间的比较,而折线图用于显示数据随时间或其他连续变量的变化趋势。 要创建一个ECharts折线图,首先需要引入ECharts库,并创建一个容器用于显示表。然后,通过配置项来定义表的样式、数据和交互行为。 下面是一个简单的示例代码,展示如何创建一个ECharts折线图: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts折线图</title> <script src="https://cdn.jsdelivr.net/npm/echarts@5.0.0/dist/echarts.min.js"></script> </head> <body> <div id="chart" style="width: 600px;height: 400px;"></div> <script> // 初始化表实例 var chart = echarts.init(document.getElementById('chart')); // 配置项 var options = { title: { text: '折线图示例' }, xAxis: { type: 'category', data: ['类别1', '类别2', '类别3', '类别4', '类别5'] }, yAxis: [ { type: 'value', name: '' }, { type: 'value', name: '折线图' } ], series: [ { name: '', type: 'bar', data: [120, 200, 150, 80, 70] }, { name: '折线图', type: 'line', yAxisIndex: 1, data: [220, 180, 120, 160, 200] } ] }; // 使用配置项显示表 chart.setOption(options); </script> </body> </html> ``` 在上述代码中,我们首先引入了ECharts库的JS文件。然后,创建一个div元素作为表的容器,并通过`echarts.init()`方法初始化表实例。 接下来,我们定义了配置项`options`,其中包括了标题、x轴和y轴的配置,以及折线图的数据配置。 最后,我们使用`chart.setOption(options)`方法来显示表。 请注意,以上代码仅为示例,你可以根据自己的需求调整配置项和数据来创建不同样式的ECharts折线图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值