Last active
January 7, 2017 17:32
-
-
Save FarazPatankar/23a9a1b473575bc22b3c839b47698f96 to your computer and use it in GitHub Desktop.
A helper function to draw values on a chart created using ChartJS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var drawBarValues = function(el) { | |
| var ctx; | |
| ctx = el.chart.ctx; | |
| ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, 'normal', Chart.defaults.global.defaultFontFamily); | |
| ctx.fillStyle = el.chart.config.options.defaultFontColor; | |
| ctx.textAlign = 'center'; | |
| ctx.textBaseline = 'bottom'; | |
| el.data.datasets.forEach(function(dataset) { | |
| var i, model, originalValue; | |
| i = 0; | |
| while (i < dataset.data.length) { | |
| if (dataset.hidden === true && dataset._meta[Object.keys(dataset._meta)[0]].hidden !== false) { | |
| i++; | |
| continue; | |
| } | |
| model = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._model; | |
| ctx.fillText(dataset.data[i], model.x - 1, model.y - 5); | |
| i++; | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment