在绘制实时数据时,Highchart性能会变慢

[英]Highchart performance slow on plotting live data


I am plotting live data in Highchart's(4.2.4) Line type chart for each second data i.e. 60 points for 1 min. and requirement is to collect each second data for long duration. I am using below code to add point in series. The number of series I have is 20. And for each series I have to add point per second. The turboThreshold set for each series is also around 2000. And slicing should be done after 1000 points data.

我正在Highchart(4.2.4)线型图表中为每个第二个数据绘制实时数据,即60分,1分钟。并且要求是长时间收集每个第二数据。我使用下面的代码来串行添加点。我拥有的系列数是20.而对于每个系列,我必须每秒添加点数。每个系列的turboThreshold设置也在2000左右。切片应该在1000点数据之后完成。

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

I see a very low performance my browser keeps hanging and also chart is very irresponsive after some time. What can I do for better performance? I have tried below stuff: 1) Off the animation for series :

我看到一个非常低的性能,我的浏览器一直挂着,并且图表在一段时间后非常反应迟钝。我能做些什么才能获得更好的表现?我尝试了下面的东西:1)关闭系列的动画:

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

2) Turn off animation and redrawing on addpoint to the chart

2)关闭动画并重新绘制添加点到图表

3) Turn off markers for series

3)关闭系列标记

4) Included boost.js module in application

4)在应用程序中包含boost.js模块

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

1 个解决方案

#1


0  

Without your actual code I can only speculate what you're doing, but my assumption is you're trying to redraw the chart every time you add a point, that would be 20 redraws per second, which is pretty excessive and will probably take more than 1 second to complete the redraws which means there will be new points added while old ones are still being drawn. Set the redraw to false on adding points and manually redraw every second or at random.

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

Example code:

$(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)]
    });
  });
});

Fiddle at http://jsfiddle.net/62k8sryc/1/

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

NOTE

Because this is JavaScript it heavily depends on browser build/version and machine specs.

因为这是JavaScript,它在很大程度上取决于浏览器构建/版本和机器规格。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2016/07/06/6f99b1725b89546f53e795fb18b5fae4.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告