在过去的几天里,我在外部文件中的一些示例 json 数据中使用 ajax 来使用 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);
I get:
[Object, Array[2]] // where the Object contains .name and .type and the Array[2] is my data
我很确定我需要这个:
[Object] // which contains .data , .name, .type