score:1

EDITED based on updated question details

OK, so, looking again at what you posted as your example data, your data is already in an array, so I am not seeing what needs a loop.

All you need to do is build your series in the chart options, and populate the `data` with the `Cur` and `Pre` arrays:

``````series: [{
'name': 'Previous',
'color': '#2dbdda',
'data': Cur
}, {
'name': 'Current',
'color': '#214881',
'data': Pre
}]
``````

.

``````Cur[0] = 3
Cur[1] = 5
Cur[2] = 4
``````

Is the same as

``````Cur = [3,5,4]
``````

Simplified fiddle with no loop:

Old answer here still, in case I've misunderstood what you're actually doing:

The loop that currently have is explicitly generating a new series on each iteration.

If you have a set number of series, you need to create the series object separately, prior to looping through the data.

If you have a dynamic number of series, you will need a nested loop to build them.

Assuming that you are only looking at two series, and want the data to be dynamic, you can build the series first, and then loop through and populate the data, like this:

``````    //build the series placeholders, with empty data arrays
var series = [{
'name': 'Previous',
'color': '#2dbdda',
'data': []
}, {
'name': 'Current',
'color': '#214881',
'data': []
}],
Cur = [4, 5, 9, 8, 7], <-- example array; populate from your database
Pre = [8, 6, 8, 1, 2];

//loop through and push the data to your series data arrays
for (var i = 0; i <= (Cur.length - 1); i++) {
series[0].data.push([Pre[i]]);
series[1].data.push([Cur[i]]);
}
``````

Example: