气泡图需要json格式。 数据来自数据库,格式为json。我使用的 json 格式存在一些问题。 这是我的代码和 json 格式
$(function() {
$.getJSON("scatter.json", function(json3) {
var chart;
chart = new Highcharts.Chart({
chart: {
type: 'bubble',
renderTo: 'container4',
plotBorderWidth: 1,
zoomType: 'xy'
},
title: {
text: 'Cost, Profit and Revenue'
},
subtitle: {
text: 'for 2012'
},
xAxis: {
gridLineWidth: 1,
title: {
style: {
fontSize: '9px',
}
},
},
yAxis: {
startOnTick: false,
endOnTick: false,
title: {
text: 'In Dollars'
},
max:500000,
min:0
},
series: [{
name: 'companyA',
data: json3[0]
}, {
name: 'companyB',
data: json3[1]
}]
});
});
});
这是 json 数据:
[[ { "月份": "七月", "成本": "632678", "利润": "457695", "收入": "637845"}, { "月份": "八月", "成本": "776344", "利润": 356179", "收入": "593207"}, { "月份": "九月", "成本": "248527", "利润": "70855", "收入": "532231"}, { "月份": "十月", "成本": "286024", "利润": "451776", "收入": "217594"} ],[ { "月份": "八月", "成本": "776344", "利润": "356179", "收入": "593207"}, { "月份": "九月", "成本": "248527", "利润": "70855", "收入": "532231"}, { "月份": "10 月", "成本": "286024", "利润": "451776", "收入": "217594"}]]
最佳答案
您的 JSON 中有错误。在第二个数组中,属性“Profit”的值之前缺少第一个引号。要验证您的 JSON,您可以使用此页面:http://jsonlint.com/ 。请看这个例子:http://jsfiddle.net/tbb71s88/3/ .
series: [{
name: 'companyA',
data: results[0]
}, {
name: 'companyB',
data: results[1]
}]
你想实现这样的目标吗?要实现此功能,您需要更改 JSON 结构以适应气泡系列数据,如下所述:http://api.highcharts.com/highcharts#plotOptions.bubble .
关于javascript - highchart气泡图动态-json格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38185019/