我正在尝试使用带有多个标签的chart.js绘制条形图,以便可以对其进行操作。我设法通过折线图做到了这一点,并尝试在没有运气的情况下扩展了我在那做的事情。我收到此错误。是什么原因造成的?
“未捕获的TypeError:非对象上调用了Object.defineProperty”。
问题出在数据中的某个地方:{},因为当我将数据作为一个简单的2索引数组时,它工作正常。
编辑:单步执行数据集= null时;
var com_passed = rows[rows.length-2]["# Common Passed"];
var com_failed = rows[rows.length-2]["# Common Failed"];
var ctx = document.getElementById("common_chart");
ctx.height = 50;
var historicalChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Passed", "Failed"],
datasets: [
{
data: com_passed,
label: "Passed",
fillColor: "red"
},
{
data: com_failed,
label: "Failed",
fillColor: "green"
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
responsive: false,
maintainAspectRatio: true
}
}]
}
}
});
对于那些有类似问题的人。我需要使数据com_passed和com_failed作为数组而不是像这样的整数。
var com_passed = rows[rows.length-2]["# Common Passed"];
var com_failed = rows[rows.length-2]["# Common Failed"];
var ctx = document.getElementById("common_chart");
ctx.height = 50;
var historicalChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Passed", "Failed"],
datasets: [
{
data: [com_passed],
label: "Passed",
fillColor: "red"
},
{
data: [com_failed],
label: "Failed",
fillColor: "green"
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
responsive: false,
maintainAspectRatio: true
}
}]
}
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句