Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple series in Highcharts within a loop

I need to create multiple series for a highcharts based on a array variable. IF the array has 5 elements then create 5 series, if the array has 4 elements then create 4 series and so on. How do i do this? I'm using JQuery to create the charts and using Ajax, i send and recieve JSON data from my Java class.

like image 725
redwolf_cr7 Avatar asked Dec 21 '22 02:12

redwolf_cr7


1 Answers

Only what you need is use loop which push element of array to series object.

var array = [10,20,30,40,50]

var series = [],
    len = array.length,
    i = 0;

for(i;i<len;i++){
    series.push({
        name: 'serie'+i,
        data:[array[i]]
    });
}

Example: http://jsfiddle.net/Dxr6d/

like image 60
Sebastian Bochan Avatar answered Feb 13 '23 02:02

Sebastian Bochan