redwolf_cr7
redwolf_cr7

Reputation: 2047

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.

Upvotes: 4

Views: 7807

Answers (1)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

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/

Upvotes: 11

Related Questions