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:
Source: stackoverflow.com
Related Query
- How to dynamically populate Highcharts column chart with two series
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- How to Create a Stacked Column Chart with Dynamic Series in Highcharts
- Highcharts 3.0, area chart with stacked and unstacked series - how to fix?
- How to change color of bar in column chart with different level of percentage in highcharts
- How to set column width for columnRange chart with multiple series
- How to make split grouped column bar chart in highcharts with percentage?
- HighCharts column chart populated with series data from a function
- Highcharts column chart with two different scales
- How to have multiple highcharts with different series data in vuejs without repeating code
- How to reference yData from another series in each category of a highcharts column chart
- Highcharts column how to move series name to the title position with bigger text size
- Update two series on the same graph dynamically with HighCharts
- How to dynamically addEvent to Highcharts series with multiple charts?
- highcharts column : add dynamically series with drilldown data
- Highcharts, chart with two series starting in diferent points, how yo show single column?
- Column chart in Highcharts - select series with a click
- How to render a bar chart with different series with only one entry per category in HighCharts
- How to use trellis chart with stacked column in Angular 10 using Highcharts
- How to dynamically remove the whole Column from a single series HighCharts column graph?
- Highcharts column + line combination chart with multiple series
- Highcharts : How to align column chart and bubble chart vertically in the same series
- How to create a column range chart in Highcharts using range and navigator functions?
- Highcharts - how to have a chart with dynamic height?
- How to show a column with the value Zero in Column chart in Highcharts?
- How To Use Epoch Time With Highcharts Series Data?
- Highcharts : Chart with drilldown how to obtain click event of drill up button
- Add a gap between the second and third series in a Highcharts column plot with four series displayed
- Highcharts - best way to handle and display zero (or negative) values in a line chart series with logarithmic Y axis
- Highcharts Column chart with drilldown, remove hyperlink like formatting from x-axis labels
More Query from same tag
- Highcharts negative logarithmic scale solution stopped working
- Highcharts Boxplots How to get five point summary?
- How to show unique name of every points in highCharts using angular
- highchart x axis not showing correct date labels
- Highcharts date not working
- How to create a chart with X and Y as strings?
- Highstock columnrange data grouping values not consistent
- How to create 2 separated xAxis chart
- Element not found SteamDB - Selenium
- Highcharts: Change the Legend TItle on drilldown
- Highcharts - Display only specific series in specific category?
- Can i add two axis in a spiderweb highcharts and click x-axis label navigate to another page?
- Highcharts container wider than parent div
- HighCharts.js is not rendering chart under IE8
- Highstock dateTimeLabelFormats doesn't work
- How to reference series in Highcharts v.4?
- Highcharts export module: Multiple Phantom JS instance in jBoss
- High Chart to High Stock
- Django - 'SafeText' object has no attribute 'get'
- Overlapping of highchart with it's series text
- Strange behavior with highcharts when using "column" type and multiple datetime series
- Highcharts xrange chart is not respecting datetime xAxis min and max values - shows space on both sides
- level series in a highchart
- TCPDF not rendering dots (circles) with path variables in text file using imageSVG
- Show checkboxes within diagram legend does not work well if scrollablePlotArea is configured
- Can not get series data in Highcharts, Highstock
- Highcharts - Sunburst partition
- Highchart: To display percent on each and every column of Column chart
- How to add mean in a boxplot made with highcharter?
- Is it wise to disable browser link option in Visual Studio?