我需要向数据集/标签添加一个属性以在单击时识别它。我试过这样的事情:
Chart.controllers.customBar = Chart.controllers.bar.extend({
code: null
});
它几乎可以工作,因为我可以看到新属性“代码”,数据与之关联,图表背景可见但为空,我的意思是数据集中没有可见的数据。
这是我的初始化:
var ctx = document.getElementById("roads-chart").getContext("2d");
window.roadsBar = new Chart(ctx, {
type: 'bar',
data: roadsChartData,
options: {
title: {
display: true,
text: "Stan dróg"
},
tooltips: {
mode: 'label'
},
responsive: true,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
},
onClick: function(e, d) {
console.log(d);
}
}
});
问题是,我感觉不到 Chart.js,有人可以帮我处理它并举例说明扩展是如何工作的吗?:)
谢谢