過去幾天我一直在遇到一些問題,在某些外部文件的示例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