我正在尝试使用chart.js绘制图表。我的用例非常简单,我从数据库中获取需要绘制在折线图上的数据。使用硬编码数据(即)时,我能够使图表正常工作
yes
尝试用变量数组替换数据:[1,2,3]时,控制台出现错误:
data: {
labels: ["January", "February", "March"],
datasets: [{
label: "Occupancy",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [1,2,3],
}]
},
然后会出现以下错误:
var occ_labels = $('.chart_data_class')[0].dataset['occLbl'];
//var occ_labels =["1","2","3"];
console.log(occ_labels);
var occ_twentyfive = $('.chart_data_class')[0].dataset['occ-25'];
var ctx_occ = document.getElementById('occ-chart').getContext('2d');
console.log(ctx_occ);
var chart = new Chart(ctx_occ, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels: ["January", "February", "March"],
datasets: [{
label: "Occupancy",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: occ_twentyfive,
}]
},
// Configuration options go here
options: {
legend: false,
}
});
var ctx_adr = document.getElementById('adr-chart').getContext('2d');
除了该变量外,其他都没有改变。该变量有效,并已在控制台中打印。我也尝试过如下设置变量:
jquery3.self-5af507e253c37e9c9dcf65064fc3f93795e6e28012780579975a4d709f4074ad.js?body=1:3828 Uncaught TypeError: Object.defineProperty called on non-object
at Function.defineProperty (<anonymous>)
at e (Chart.min.js:12)
at a.buildOrUpdateElements (Chart.min.js:12)
at t.Controller.<anonymous> (Chart.min.js:11)
at Object.o.each (Chart.min.js:12)
at t.Controller.update (Chart.min.js:11)
at t.Controller.initialize (Chart.min.js:11)
at new t.Controller (Chart.min.js:11)
at new t (Chart.min.js:12)
at HTMLDocument.<anonymous> (interest.self-8876b9dfa2300b4adb2cc9db31f03dcc885a83d23bfc2247d8c08fa65a545fe9.js?body=1:16)
,这也不起作用。有什么想法吗?我花了最后几个小时来弄清楚问题出在哪里,而我却找不到问题所在。
答案 0 :(得分:0)
令人惊讶的是,我只是回到页面,这似乎是现在的工作,即使我以前多次启动和重新启动服务器。也许有什么东西在缓存某处,等待几天再试固定它在某种程度上。不知道发生了什么事...