Using Chart.js I declare two charts, using the same options. I would like to have different titles for the charts. But titles are declared in options.
I tried, adding title: after the opt that are used for both charts. But this did not work.
var ctx = document.getElementById("myChart");
myLineChart = new Chart(ctx, {
type: 'horizontalBar',
data: chartData,
options: opt,
title: {
display: true,
text: 'title',
}
});
var ctx2 = document.getElementById("myChart2");
myLineChart = new Chart(ctx2, {
type: 'horizontalBar',
data: chartData2,
options: opt,
title: {
display: true,
text: 'title2',
}
});
And the var options are:
var opt = {
events: false,
legend: {
display: false
},
scales: {
xAxes: [{
ticks: {
display: true,
callback: function(value, index, values) {
return Intl.NumberFormat('$form->{countrycode}').format((value));
}
}
}]
},
responsive: false,
tooltips: {
enabled: false
},
hover: {
animationDuration: 0
},
animation: {
duration: 1,
onComplete: function() {
var chartInstance = this.chart;
ctx = chartInstance.ctx;
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function(dataset, i) {
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function(bar, index) {
var data = '$form->{currency}' + Intl.NumberFormat('$form->{countrycode}').format(dataset.data[index]);
ctx.fillText(data, bar._model.x + 10, bar._model.y - 1);
});
});
}
}
};