Highcharts 折线图显示多个属性数据

1.数据结构

   [{ "name": "事件1", "data": [{ "x": toUTC("2021-07-10 10:10:01"), "y": 4, "z": 'aaa' }, { "x": toUTC("2021-07-11 10:10:01"), "y": 4, "z": 'aaa' }, { "x": toUTC("2021-07-12 10:10:01"), "y": 4, "z": 'aaa' }] }]

2.组织数据

var OnLine = [];//在线的
    function SearchBSonlineLadlesUsedTimes() {
        $.post("/Home/SearchBSonlineLadlesUsedTimes", {}, function (result) {
            var v = eval(result);
            let array = [];
            for (var i = 0; i < v.length; i++) {
                var c = array.filter(d=>d.name == v[i].ladleNO);
                if (c.length > 0) {
                    c[0].data.push({ x: toUTC(formatDate(new Date(parseInt(v[i].createTime.substr(6))))), y: v[i].maxTemp, z: v[i].usedTimes });
                } else {
                    OnLine.push(v[i].ladleNO);
                    array.push({ name: v[i].ladleNO, data: [{ x: toUTC(formatDate(new Date(parseInt(v[i].createTime.substr(6))))), y: v[i].maxTemp, z: v[i].usedTimes }] });
                }
            }
            Show1("sstjt", array);
        });
    }

3.显示

function Show1(id, array) {
        Highcharts.setOptions({
            time: {
                useUTC: false
            }
        });
        var sstjt = Highcharts.chart(id, {
            chart: {
                type: 'line',
                //inverted: true
                backgroundColor: 'rgba(0,0,0,0)',
            },
            title: {
                text: '在线钢包最近炉次实时统计图',
                style: {
                    color: '#fff',
                    fontSize: '14px',

                },
                align: 'left',
                verticalAlign: 'top',
            },
            credits: {
                enabled: false//不显示LOGO
            },
            subtitle: {
                text: null
            },
            xAxis: {
                type: 'datetime',
                labels: {
                    step: 1,//x轴间隔
                    formatter: function () {
                        return Highcharts.dateFormat('%Y-%m-%d', this.value);//%Y-%m-%d %H:%M
                    }
                }
            },
            yAxis: {
                title: {
                    text: '温度(℃)',
                },
                labels: {
                    formatter: function () {
                        return this.value + '';
                    },
                    style: {
                        color: '#999',
                        fontSize: '12px'
                    }
                },
                lineWidth: 0,
                lineColor: '#666',
                gridLineWidth: 1,
                gridLineColor: '#3b4159',
                gridLineDashStyle: 'solid',
            },
            colors: ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', '#f15c80', '#e4d354', '#8085e8', '#8d4653', '#91e8e1'],
            legend: {
                enabled: true,
                align: 'right',
                verticalAlign: 'top',
                y: -50,
                itemStyle: { cursor: 'pointer', color: '#fff', fontWeight: 'none', },
                itemHiddenStyle: { color: '#666' },
                itemHoverStyle: { color: '#666' },
                itemDistance: 5
            },
            tooltip: {
                crosshairs: true,
                shared: false,//鼠标移上去分开显示数据标签
                headerFormat: '钢包号:{series.name}',
                pointFormat: '<br>最高温:{point.y}℃<br>第:{point.z}次'
            },
            plotOptions: {
                spline: {
                    lineWidth: 2,
                    states: {
                        hover: {
                            lineWidth: 2
                        }
                    },
                    marker: {
                        enabled: false
                    }
                },
                line: {
                    dataLabels: {
                        // 开启数据标签
                        enabled: true,
                        pointFormat: '{point.y}℃(第{point.z}次)',
                        style: {
                            color: '#fff',
                            fontSize: '12px',
                            fontWeight: 'none'
                        }
                    },
                    // 关闭鼠标跟踪,对应的提示框、点击事件会失效
                    enableMouseTracking: true
                }
            },
            series: array//[{ "name": "事件1", "data": [{ "x": toUTC("2021-07-10 10:10:01"), "y": 4, "z": 'aaa' }, { "x": toUTC("2021-07-11 10:10:01"), "y": 4, "z": 'aaa' }, { "x": toUTC("2021-07-12 10:10:01"), "y": 4, "z": 'aaa' }] }]
        });
    }
    //转UTC时间
    function toUTC(time) {
        var date = new Date(time);
        var y = date.getUTCFullYear();
        var m = date.getUTCMonth();
        var d = date.getUTCDate();
        var h = date.getUTCHours();
        var M = date.getUTCMinutes();
        var s = date.getUTCSeconds();
        return Date.UTC(y, m, d, h, M, s);
    }
    function formatDate(date) {
        var d = new Date(date),
          month = '' + (d.getMonth() + 1),
          day = '' + d.getDate(),
          year = d.getFullYear();

        if (month.length < 2) month = '0' + month;
        if (day.length < 2) day = '0' + day;

        return [year, month, day].join('-');
    }

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值