Highcharts dynamically add series

I want to add some series (I get the series data from the webservice as a 3dim array (and return it as json) - I do not know the number of series that I will get, so I have to load the series data dynamically).

In javascript, I create an object: (for example, this high-level example: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo / compare / )

seriesOptions[i] = { name: namearray[i], data: dataarray }; eg result: [Object { name="Series", data=[[1041375600000, 29,9]]}] 

I tried to add a series as follows:

 $.each(seriesOptions, function (itemNo, item) { chart.addSeries({ name: item.name, data: item.data }, false); }); chart.redraw(); 

But the diagram draws a series of the genus weird and does not convert to a timestamp today. Are there any problems with my chart data from webservice?

Here is my code: http://jsfiddle.net/DGdaf/2/

Thanks for any help.

EDIT
The chart seems to ignore all the default values โ€‹โ€‹for the timeline / scaling value. I have no idea why it does not display these components.
The problem may be that I am drawing a chart after initialization?

 chart = new Highcharts.Chart(options); 

But I have to do this to load the dynamic series.

EDIT2
I'm not sure if I upload too much data or something like that. I cannot create my series dynamically.

 for(i=0; i<seriesOptions.length; i++){ chart.addSeries({ name: seriesOptions[i].name, data: seriesOptions[i].data }, true); }; 
+4
source share
1 answer

Set for yAxis:

 yAxis: { type: 'datetime' } 

See fiddle

EDIT: Timing / scaling http://jsfiddle.net/DGdaf/5/

Edit: Use the callback to add a series when the schedule is ready. However, why don't you add these series when creating your chart?

  chart = new Highcharts.Chart(options, function(ch) { $.each(seriesOptions, function (itemNo, item) { ch.addSeries({ name: item.name, data: item.data }, false); }); chart.redraw(); }); 
+4
source

Source: https://habr.com/ru/post/1487445/


All Articles