【发布时间】:2025-12-23 05:40:11
【问题描述】:
在过去的几天里,我遇到了一些问题,即使用 Highcharts 库从外部文件中 ajaxing 一些示例 json 数据来填充饼图。
这是我在文件中的示例 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
【问题讨论】:
-
你解决了这个问题吗,我也有同样的问题,如果你和我分享一下
标签: ajax json highcharts