最佳答案
以下答案仅适用于 Chart.js v2。
如果您想要 v1 解决方案,请检查 pritishvaidya's .
您想使用图表选项的 animation
属性:
options : {
animation: {
duration: 500,
onComplete: function () {
// The code here will be executed at the end of the animation
// (after 500ms here)
// You can get the canvas context using the following :
var ctx = this.chart.ctx;
// `this` being the chart instance
}
}
}
现在你想在它上面添加点的值,这可以使用数据模型来完成,你可以在数据集属性中找到它:
onComplete: function() {
// You get the canvas context, to help you writing what you want
var ctx = this.chart.ctx;
// Here you set the context with what you need (font, size, color ...)
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.fillStyle = 'black';
// For every dataset ...
this.data.datasets.forEach(function(dataset) {
// For every data in the dataset ...
for (var i = 0; i < dataset.data.length; i++) {
// We get its model
var model = dataset._meta[0].data[i]._model;
// And write the data above it
ctx.fillText(dataset.data[i], model.x, model.y - 2);
// You can edit the last two arguments according to what you need
}
});
}
按照上面代码的结果,你可以找到on this jsFiddle :
关于javascript - Chartjs 雷达索引标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39974482/