As for the original solution for displaying the data value using the Canvas fillText() HTML5 method in animation onComplete , the code below will help you what you need:
The key to custom displaying any data related to the chart is checking the chart data set as shown below in this.data.datasets . I did this by checking where the different values ββin this dataset are located, as well as the position to place them for the fillText method.
Checking Chart Dataset: Image
Script (Chart.js 2.0 and higher):
var barOptions = { events: false, showTooltips: false, legend: { display: false }, scales:{ yAxes: [{ display: false }] }, animation: { onComplete: function () { var ctx = this.chart.ctx; ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily); ctx.textAlign = 'left'; ctx.textBaseline = 'bottom'; this.data.datasets.forEach(function (dataset) { for (var i = 0; i < dataset.data.length; i++) { var model = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._model, left = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._xScale.left; ctx.fillStyle = '#444';
jsFiddle: http://jsfiddle.net/jfvy12h9/
Hung tran
source share