Echarts分段不同样式图形显示

这段代码展示了如何使用ECharts进行数据可视化,包括时间序列数据的显示、线条平滑处理、多数据系列对比以及自定义提示框内容。通过设置animationDuration、tooltip、xAxis和yAxis等属性,实现了动画效果和轴标签的旋转与格式化。
摘要由CSDN通过智能技术生成

效果:

 

代码:

option = {
    animationDuration: 3000,
    tooltip: {
        trigger: 'axis',
        formatter: function(params) {
            var str = params[0].axisValue + "<br />";
            var n = []; //一个新的临时数组
            var m = [];
            console.log(params)
            for (var i = 0; i < params.length; i++) {
                if (params[i].data) {
                    n.push(params[i].marker + params[i].seriesName + ":" + params[i].data + "<br/>");
                }
            }
            for (var j = 0; j < n.length; j++) //遍历当前数组
            {
                //如果当前数组的第i已经保存进了临时数组,那么跳过,
                //否则把当前项push到临时数组里面
                if (m.indexOf(n[j]) == -1) m.push(n[j]);
            }
            for (var k = 0; k < m.length; k++) {
                str += m[k];
            }
            return str;
        }
    },
    xAxis: {
        type: "category",
        data: ['2022-03-18 07:00', '2022-03-18 08:00', '2022-03-18 09:00', '2022-03-18 10:00', '2022-03-18 11:00', '2022-03-18 12:00', '2022-03-18 13:00', '2022-03-18 14:00', '2022-03-18 15:00', '2022-03-18 16:00', '2022-03-18 17:00', '2022-03-18 18:00', '2022-03-18 19:00', '2022-03-18 20:00', '2022-03-18 21:00', '2022-03-18 22:00'],
        boundaryGap: false,
        axisLabel: {
            interval: 0,
            rotate: 0,
            formatter: function(value, index) {
                var date = new Date(value);
                return date.getHours() + "点";
            },
        },
        axisLine: {
            lineStyle: {
                type: "solid",
                color: "#00b0d5",
                width: "1",
            },
        },
    },
    yAxis: {
        name: "PM10",
        scale: true,
        splitNumber: 2,
        axisLine: {
            show: true,
            lineStyle: {
                type: "solid",
                color: "#00b0d5",
                width: "1",
            },
        },
        splitLine: {
            show: false,
        },
    },
    grid: {
        left: "1%",
        top: "20%",
        right: "5%",
        bottom: "10%",
        containLabel: true,
    },
    series: [{
            type: "line",
            name: "华阳",
            smooth: true,
            data: [19, 21, 18, 15, 17, 16, 19, 21, 20, 22, 23, 26, 25, null, ],
        },
        {
            type: "line",
            name: "华阳",
            smooth: true,
            itemStyle: {
                normal: {
                    lineStyle: {
                        width: 2,
                        type: 'dotted' //'dotted'虚线 'solid'实线
                    }
                }
            },
            data: [null, null, null, null, null, null, null, null, null, null, null, null, 25, 21, 28, 33],
        },
        {
            type: "line",
            name: "仙霞",
            smooth: true,
            data: [18, 22, 17, 14, 16, 17, 22, 23, 23, 25, 24, 29, 35, null, ],
        },
        {
            type: "line",
            name: "仙霞",
            smooth: true,
            itemStyle: {
                normal: {
                    lineStyle: {
                        width: 2,
                        type: 'dotted', //'dotted'虚线 'solid'实线
                    }
                }
            },
            data: [null, null, null, null, null, null, null, null, null, null, null, null, 35, 31, 18, 23],
        },

    ],
};
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值