highcharts 绘制实时数据时Highchart性能缓慢

s4n0splo  于 9个月前  发布在  Highcharts
关注(0)|答案(1)|浏览(167)

我在Highchart的(4.2.4)线型图中绘制实时数据,每秒钟的数据,即。60分1分钟并且要求长时间地收集每秒的数据。我使用下面的代码来添加点在系列. * * 对于每一个系列,我必须每秒增加一点。每个系列的turboThreshold设置也在2000左右。并且切片应该在1000个点数据之后进行。

chart.series[0].addPoint(point, false, data > 1000?shift: false, false);

我看到一个非常低的性能,我的浏览器一直挂起,也图表是一段时间后非常没有React。我能做些什么来获得更好的性能?我试过下面的东西:1)关闭动画系列:

plotOptions: {
                            series: {
                                animation:false,
                                states: {
                                    hover: {
                                        lineWidthPlus: 0
                                    }
                                }
                            }
                        },

2)关闭图表添加点上的动画和重绘
3)关闭系列的标记
4)在应用程序中包含boost.js模块

script src="https://code.highcharts.com/modules/boost.js"
pu3pd22g

pu3pd22g1#

没有你的实际代码,我只能推测你在做什么,但我的假设是,你试图在每次添加一个点时重新绘制图表,这将是每秒20次重新绘制,这是相当过分的,可能需要超过1秒的时间来完成重新绘制,这意味着将有新的点添加,而旧的点仍在绘制。添加点时将重绘设置为false,然后每秒或随机手动重绘。
示例代码:

$(function() {

  var series = function(i) {
    return {
      name: 'Random data '+i,
      data: (function() {
        // generate an array of random data
        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;
      }())
    };
  };

  $(document).ready(function() {
    Highcharts.setOptions({
      global: {
        useUTC: false
      }
    });

    $('#container').highcharts({
      chart: {
        type: 'line',
        animation: Highcharts.svg, // don't animate in old IE
        marginRight: 10,
        events: {
          load: function() {
                        var chart = this;
            // set up the updating of the chart each second            
              setInterval(function() {
                for (var i = 0; i < 20; i++) {              
                var series = chart.series[i];
                var x = (new Date()).getTime(), // current time
                  y = Math.random();
                  series.addPoint([x, y], false, false,false);
                }
                chart.redraw();
              }, 1000);            
          }
        }
      },
      title: {
        text: 'Live random data'
      },
      xAxis: {
        type: 'datetime',
        tickPixelInterval: 150
      },
      yAxis: {
        title: {
          text: 'Value'
        },
        plotLines: [{
          value: 0,
          width: 1,
          color: '#808080'
        }]
      },
      tooltip: {
        formatter: function() {
          return '<b>' + this.series.name + '</b><br/>' +
            Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
            Highcharts.numberFormat(this.y, 2);
        }
      },
      exporting: {
        enabled: true
      },      
      plotOptions: {
        series: {
            marker: {
            enabled: true
          }
        }
      },
      series: [series(1), series(2),series(3), series(4),series(5), series(6),series(7), series(8),series(9), series(10),series(11), series(12),series(13), series(14),series(15), series(16),series(17), series(18),series(19), series(20)]
    });
  });
});

小提琴http://jsfiddle.net/62k8sryc/1/

备注

因为这是JavaScript,它严重依赖于浏览器构建/版本和机器规格。

相关问题