Javascript 用对象数组填充highchart行
我使用highchart js创建折线图。我使用php进行json响应。 问题是,当我根据响应填充图表时,显示的是年份,而不是线条Javascript 用对象数组填充highchart行,javascript,php,highcharts,Javascript,Php,Highcharts,我使用highchart js创建折线图。我使用php进行json响应。 问题是,当我根据响应填充图表时,显示的是年份,而不是线条 $(document).ready(function () { $.ajax({ type: "GET", url: 'resp_highChart.php', dataType: "json", contentType: "application/json", success:
$(document).ready(function () {
$.ajax({
type: "GET",
url: 'resp_highChart.php',
dataType: "json",
contentType: "application/json",
success: function (response) {
console.log(response);
// draw chart
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Year Wise Sales Data'
},
subtitle: {
text: ''
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr']
},
yAxis: {
title: {
text: 'Sold Value'
},
labels: {
formatter: function () {
return this.value + '';
}
}
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
}
},
series: response
});
}
});
});
我的答复格式如下
[{"name":"2012","data":"[692101643,716334837,776991835,769420169 ]"},{"name":"2013","data":"[860859252,825852169,895524501,892930333 ]"}]
这里的问题是数据值被读取为字符串而不是数组 我使用图表选项和直接插入的JSON数据创建了一个fiddle示例: 图表的格式如下所示。请注意,数据数组周围没有引号
series: [
{"name":"2012","data":[692101643,716334837,776991835,769420169 ]},
{"name":"2013","data":[860859252,825852169,895524501,892930333 ]}
]
我希望这对你有帮助
另外,非常感谢您在问题中包含示例数据。这非常有帮助。感谢您的回答。我正在使用json_encode将响应转换为json,因为数据数组中添加了引号。因此,如何从数据数组中删除引号。我发现了一些堆栈溢出帖子,可能有助于您删除这些引号:1);2) ; 3) ; 4) 谢谢你的快速回复…这些帖子真的很有帮助