I have a bar chart (using chart.js) with labels as images and when i try to export the canvas to image it only exports the chart part not the images(labels), but the same canvas when I right click and save as image is able to exporting correctly (both the chart and label images).
Can someone help me with this issue.
my js file:
var config = {
type: 'horizontalBar',
data: {
labels:['a', 'b', 'c', 'd', 'e', 'f'],
datasets: [
{
data: [ "20", "10", "2", "5", "1", "22" ],
backgroundColor: [ '#f1f33a', '#99d695', "#cc8e50", '#ec9089', '#8e7bd4', '#eef5ce' ]
}]
},
options: {
animation: {
duration: 1,
onComplete: function(charttt) {
var chartInstance = charttt.chart,
ctx = chartInstance.ctx;
ctx.textAlign = 'right';
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function (dataset) {
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function (bar, index) {
var img = new Image();
img.src = 'https://i.imgur.com/yDYW1I7.png';
var data = dataset.data[index];
ctx.fillStyle = 'red';
ctx.fillText(data, bar._model.x - 20, bar._model.y - 10);
img.onload = function() {
ctx.drawImage(img, bar._model.x, bar._model.y, 10, 10);
}
});
});
var url = document.getElementById('barChart').toDataURL('image/png');
document.getElementById("testimg").src = url;
}
},
legend: {
"display": false
},
responsive:false,
chartArea: {
backgroundColor: 'blue'
}
}
};
var ctx = document.getElementById("barChart").getContext("2d");
var chartt = new Chart(ctx, config);