options: {
animation: {
duration: 2000,
onComplete: function() {
var chart = this.chart;
var ctx = chart.ctx;
this.data.datasets.forEach(function(dataset, i) {
var meta = chart.controller.getDatasetMeta(i);
if (!meta.hidden) {
meta.data.forEach(function(element, index) {
// Draw the text in black, with the specified font
ctx.fillStyle = layoutColors.defaultText;
var fontSize = 16;
ctx.font = Chart.helpers.fontString(fontSize, 'normal', 'Helvetica Neue');
// Just naively convert to string for now
var dataString = dataset.data[index].toString();
// Make sure alignment settings are correct
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
var padding = 5;
var position = element.tooltipPosition();
ctx.fillText(dataString, position.x, position.y - (fontSize / 2) - padding);
});
}
});
}
}
}
发布评论
评论(3)
options 中加入
chartjs 版本要2.5以上
参考链接
请问您如何解决的啊