过去几天我一直在遇到一些问题,在某些外部文件的示例json数据中使用ajaxing来使用Highcharts库填充饼图。Ajax JSON进入Highcharts饼图
这里是我的示例JSON数据文件:data.json
[
["Apples", 43.0],
["Pears", 57.0]
]
这是我实现highcharts和我的AJAX调用: (我省略了不相关的代码)
<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>
基本上,我想通过JSON传入options.series []。data []。当
options.series.push(json);
进行获取:
[Object, Array[2]] // where the Object contains .name and .type and the Array[2] is my data
我敢肯定,我需要这样的:
[Object] // which contains .data , .name, .type
你解决了这个问题吗我也有同样的问题,如果你确实与我分享 – ddw147