javascript - Adding series dynamically in highcharts -


(function($){   $(function () {     $(document).ready(function() {       highcharts.setoptions({         global: {           useutc: false         }       });       var i=0;       var chart = new highcharts.chart({         chart: {           type: 'spline',           renderto: 'container',           animation: highcharts.svg, // don't animate in old ie           marginright: 10,           events: {             load: function() {               // set updating of chart each second               var series = this.series[0];               setinterval(function() {                 var name = new array();                 name[0] = "random data";                 name[1] = "volvo";                 var length=chart.series.length;                 var flag=0;                 var index=0;                 var x = (new date()).gettime(), // current time                 y = math.random();                 (var k=0;k<name.length;k++) {                   for(var j=0;j<chart.series.length;j++) {                     if(chart.series[j].name==name[k]) {                       flag=1;                       index=j;                       x = (new date()).gettime();                       y = math.random();                       break;                     }                   }                   if(flag==1) {                     chart.series[index].addpoint([x, y], true, true);                     flag=0;                   } else {                     chart.addseries({name: '' + name[k] + '', data: [] });                     chart.series[length].addpoint([x, y+1], true);                     length=length+1;                   }                 }               }, 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);           }         },         legend: {           enabled: false         },         exporting: {           enabled: false         },         series: [{           name: 'random data',           data: (function() {             // generate array of random data             var data = [],             time = (new date()).gettime(),             i;             (i = -19; <= 0; i++) {               data.push({                 x: time + * 1000,                 y: math.random()               });             }             return data;           })()         }]       });     });   }); })(jquery); 

i able add series , add point in charts series add after initialization, "volvo", not drawing lines between points. might problem?

and there other way of comparing arrays , adding points without for-loop? because can millions of series @ times , don't want looping on arrays check if exists or not. there efficient way of finding wheteher list exists, , if index?

here fiddle: www.jsfiddle.net/2jylz/

it related fact have enabled shifting in addpoint() when add new serie. in other words, shifting remove first point , add new in end of serie. when have 1 point caused scenario. need disable shipfing, , when lenght of series.data achieve i.e 10 points, shifting should enabled.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -