我开始使用chart.js并尝试使用它来使它按我的意愿运作。我来到this page文档,并从那里开始举例:
HTML:
<div class="container col-md-6 offset-md-3">
<canvas id="myChart"></canvas>
</div>
JS:
let myChart= document.getElementById('myChart').getContext('2d');
new Chart(myChart, {
type: 'bar',
data: {
datasets: [{
data: [{id: 'Sales', nested: {value: 1500}}, {id: 'Purchases', nested: {value: 500}}]
}]
},
options: {
parsing: {
xAxisKey: 'id',
yAxisKey: 'nested.value'
}
}
});
这正是此处显示的内容,但它不起作用-数据未显示在图表上。我尝试使用普通数据:
let myChart= document.getElementById('myChart').getContext('2d');
new Chart(myChart, {
type: 'bar',
data: {
labels: ["A", "B", "C"],
datasets: [{
data: [1, 2, 3]
}]
},
options: {
}
});
一切正常,因此此解析存在问题。这里有人使用过它,可以告诉我我做错了什么吗?