我正在使用Chart.js Bundle和Jquery
var toll;
$.ajax({
async : false,
type : "GET",
url : "barChartData.php",
success : function(data) {
toll = data;
}
});
var barChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October','Novemeber','December'],
datasets: [
toll
]
};
上面的代码给出了以下错误:TypeError:无法在字符串'
中创建属性'_meta'答案 0 :(得分:0)
success
是一个回调函数,这意味着它仅在ajax调用完成后才执行。这意味着变量barChartData
将在toll
具有任何值之前被初始化。实际上,toll
尚未初始化,因为您只是编写了var toll;
。
toll
,并将其设置为空值。将通行费数据添加到数据集中,并在成功功能内 更新图表。
var toll = null;
var chart = ... //Hopefully you have access to the instance of your chart? If not, please show the rest of your code.
$.ajax({
async : false,
type : "GET",
url : "barChartData.php",
success : function(data) {
toll = data;
barChartData.datasets.push(toll);
chart.update();
}
});
var barChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October','Novemeber','December'],
datasets: []
};