Javascript Highcharts未加载带有json数据的图表
我正在为我的应用程序使用highcharts。当我使用下面的代码时,图表被渲染Javascript Highcharts未加载带有json数据的图表,javascript,json,highcharts,Javascript,Json,Highcharts,我正在为我的应用程序使用highcharts。当我使用下面的代码时,图表被渲染 obj.series=[{ type: 'pie', name: 'Fruits', data: [ ['Apple', 80.0], ['Mango', 20.0] ] }] obj.series.data=[['Apple', 43],['Pear',57.0]]; //this data I get from the server. 但是我需要通过对服务器进行a
obj.series=[{
type: 'pie',
name: 'Fruits',
data: [
['Apple', 80.0],
['Mango', 20.0]
]
}]
obj.series.data=[['Apple', 43],['Pear',57.0]]; //this data I get from the server.
但是我需要通过对服务器进行ajax调用来获取数据。因此,当我从服务器获取json响应并使用下面的代码设置数据时,图表不会呈现
obj.series=[{
type: 'pie',
name: 'Fruits',
data: [
['Apple', 80.0],
['Mango', 20.0]
]
}]
obj.series.data=[['Apple', 43],['Pear',57.0]]; //this data I get from the server.
你能告诉我哪里出了问题吗
我正在更新下面的完整代码:
var chartObj = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:null
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
navigation: {
buttonOptions: {
enabled: false
}
},
title:{
text: 'Storage Data'
},
series:[{
type: 'pie',
name: 'Storage Data',
/*data: [
['HP', 80.0],
['DELL', 20.0]
]*/
}]
}
var storageData = $.getJSON('http://hostname/resturl/data',
function(data) {
var result = new Array();
for (i=0;i<data.content.length;i++) {
var alpha = new Array();
alpha.push(data.content[i].x);
alpha.push(data.content[i].y);
result.push(alpha);
}
storageobj.series.data=result;
});
$('#pie-chart2').highcharts(storageobj);
请显示完整代码。请确保json中有数字值。您在控制台中收到任何错误吗?我已经用当前代码更新了问题。请告诉我哪里出错了。控制台上没有错误。当我删除
data
部分中的注释时,它可以正常加载,但是当我尝试使用ajax获取数据时,它不会呈现图表。控制台上也没有错误。请以实时方式回复您的演示