I am using Highcharts to create multiple bars on a chart and I get the data from an Ajax call.
What I encounter is linked to the format of the array I get.
What I am doing to create the array is :
elements = [];
// AJAX request here ($.getJSON(...))
$.each(data, function(key, value) {
elements.push(value.item1);
}
// End of $.getJSON
When using this method, Highcharts does not work properly, I know I can add the data another way but I would still like to solve this problem.
Here is what happens when I console.log(elements)
:
Array []
0: 0
1: 0
2: 0
3: 0
4: 0
5: 5
6: 0
length: 7
<prototype>: Array []
I can get the structure I want by writing var elements = [0, 0, 0, 0, 5, 0];
When I console.log(elements)
I get this structure :
Array(6) [ 0, 0, 0, 0, 5, 0 ]
0: 0
1: 0
2: 0
3: 0
4: 5
5: 0
length: 6
<prototype>: Array []
To me both arrays are similar but there's a difference on the first line of the console.log().
I don't really understand what is causing this.
EDIT: After the Ajax and the $.each, I create the chart, but when using an array created with
elements.push()
the chart is not created.
My problem does not come from the fact that console.log displays different things, it comes from the fact that Highcharts does not "understand" the array I am giving it.