更新画布图表中的数据点时出现问题。我收到此错误消息:
未捕获的TypeError:无法读取未定义的属性“ getTime”
我在response.msg
中收到的输出是
[{label: 'Purok I', y:1},{label: 'Purok II', y:1},{label: 'Purok III', y:2}]
将其替换为response
会成功呈现图表。但是,将响应传递给datapoints
会产生错误。这是我的Javascript。有帮助吗?
$('#barangay-list').click(function() {
var barangay_id = $(this).val()
console.info(barangay_id)
$.ajax({
url: '../classes/main.php',
type: 'POST',
data: {
'population-chart': 1,
'barangay_id': barangay_id
},
async: true,
dataType: 'JSON',
success: function(response, data) {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2",
zoomEnabled: true,
animationEnabled: true,
animationEnabled: true,
axisX: {
title: "Street Name",
gridThickness: .9,
lineThickness: .9,
titleFontSize: 14,
labelFontSize: 12,
},
axisY: {
includeZero: true,
title: "Number of Population",
gridThickness: .9,
lineThickness: .9,
titleFontSize: 14,
labelFontSize: 12
},
toolTip: {
shared: "true"
},
legend: {
cursor: "pointer",
itemclick: toggleDataSeries,
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [{
type: "spline",
showInLegend: true,
name: "Populaltion Number",
dataPoints: response.msg
}]
});
chart.render();
function toggleDataSeries(e) {
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
chart.render();
}
},
// Error Handler
error: function(xhr, textStatus, error) {
console.info(xhr.responseText);
}
});
});
答案 0 :(得分:0)
我在这种关心的人Converting array with Different data type的帮助下解决了问题
删除此代码:
char
添加JSON.parse()和地图功能
async: true,
dataType: 'JSON',