The legendCallback function is configured in the parameters launched by Chart JS, and then becomes available for your call code by calling chartInstance.generateLegend (), which will generate HTML code to add to the element on the page.
var chartInstance = new Chart(ctx, {
type: 'line',
data: data,
options: {
legendCallback: function (chart) {
console.log(chart);
return 'a';
}
}
});
var legendHtml = chartInstance.generateLegend();
source
share