highcharts 动态刷新图标多个曲线

Highcharts.setOptions({
                global: {
                    useUTC: false
                }
            });
            function activeLastPointToolip(chart) {
                var points = chart.series[0].points;
                chart.tooltip.refresh(points[points.length -1]);
            }
            var chart = Highcharts.chart('container_change', {
                chart: {
                    type: 'spline',
                    marginRight: 10,
                    events: {
                        load: function () {
                            var series = this.series[0],
                                chart = this;
                            var series2 = this.series[1],
                                chart2 = this;
                            activeLastPointToolip(chart);
                            setInterval(function () {
                                var x = (new Date()).getTime(), // 当前时间
                                    y = Math.random(),
                                    z = Math.random()*3;  // 随机值
                                series.addPoint([x, y], true, true);
                                activeLastPointToolip(chart);
                                series2.addPoint([x, z], true, true);
                                activeLastPointToolip(chart2);
                            }, 1000);
                        }
                    }
                },
                title: {
                    text: '温度时间曲线变化图'
                },
                xAxis: {
                    type: 'datetime',
                    tickPixelInterval: 150
                },
                yAxis: {
                    title: {
                        text: null
                    }
                },
                tooltip: {
                    formatter: function () {
                        return '' + this.series.name + '
' + Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '
' + Highcharts.numberFormat(this.y, 2); } }, legend: { enabled: false }, series: [{ name: '随机数据', data: (function () { // 生成随机值 var data = [], time = (new Date()).getTime(), i; for (i = -19; i <= 0; i += 1) { data.push({ x: time + i * 1000, y: Math.random() }); } return data; }()) }, { name: '随机数据2', data: (function () { $.getJSON('/myadmin/condition/room/high_data/{{ room.id }}/', function (response) { if (response.code !== 200) { alert('读取数据失败!'); return false; } var data_ = response.data; return data_.data3 }); }()) }] });

 

你可能感兴趣的:(highcharts)