I have been encountering issues for the past few days with ajaxing in some sample json data from an external file to populate a pie chart using the Highcharts library.
Here is my sample JSON data in file: data.json
[
["Apples", 43.0],
["Pears", 57.0]
]
Here is my implementation of highcharts and my AJAX call: (I have omitted unrelated code)
<script type="text/javascript">
$(function() {
var options = {
chart: {
renderTo: 'Chart',
defaultSeriesType: 'pie'
},
title: {
text:'Fruits'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
}
}
},
series: [{
type: 'pie',
name: 'Fruits',
data: []
}]
};
$.getJSON('data.json', function(json) {
options.series.push(json);
var chart = new Highcharts.Chart(options);
}).error(function() {console.log('error');});
});
</script>
Basically, I want to pass in the JSON, into options.series[].data[]. When proceed with
options.series.push(json);
I get:
[Object, Array[2]] // where the Object contains .name and .type and the Array[2] is my data
I'm pretty sure I need this:
[Object] // which contains .data , .name, .type