Load data into Highcharts with Ajax Load data into Highcharts with Ajax ajax ajax

Load data into Highcharts with Ajax


You have to use the setData methode of the series object as descriped in documentation. In your case it is options.series[0].setData(Data)

And I think you have to turn your Ajax result from string to a real object/array by using JSON.parse(data).

EDIT:@Ricardo Lohmann: in the ajax-call he did not specify the dataType he expects in the response, so jQuery will guess the dataType. But it will not recognize a string starting with [ as JSON and I doubt his response will be served with correct mime type application/json. So specifying the correct mime type should also solve the problem. But I do not have an example of the complete ajax respons of the questioner. So I'm just guessing, too.

I'd recommend the following ajax call:

$.ajax({    type: "POST",    url: "update_visits_chart",    data: {month: month},    dataType: 'json',    success: function(data){        options.series[0].setData(data);    }});

@Jugal Thakkar

$.getJSON is just a shortcut for the ajax-call above, but it is less flexible because you have less options.


You have to set directly data to series because data is already a multidimensional array.
The following code will fix it.
Change options.series.push(data); to options.series = data;