我需要使用chart.js 将文本写入图表中的条形图中
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data:data,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
},
responsive : true,
showTooltips : false,
showInlineValues : true,
centeredInllineValues : true,
tooltipCaretSize : 0,
tooltipTemplate : "<%= value %>"
});
上面的代码不起作用...
我需要这样的东西:
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
如果您想为每个元素呈现居中文本,有一个更简单的方法:
Chart.helpers.each(meta.data.forEach(function (bar, index) { var centerPoint = bar.getCenterPoint(); ctx.fillText(dataset.data[index], centerPoint.x, centerPoint.y)); }),this)似乎'getCenterPoint'在版本2.1.3中不可用(您在示例中使用的)。我用 2.5.0 尝试过,它可以工作