As in this article, chart.js allows to use plugins
https://www.chartjs.org/docs/latest/samples/legend/html.html
But I can’t find a way to use it in chartkick gem with rails.
I tried calling the plugin with
Chartkick.eachChart(function (chart) {
let options = chart.getOptions(), chart_data = options["library"]["data"];
let plugins = {
htmlLegend: {
containerID: 'legend-container',
},
legend: {
display: false
}
}
if (options['darkColors'] === true) options["dataset"]["backgroundColor"] = options['colors'];
options["library"]["plugins"] = plugins
chart.setOptions(options);
if (options.stacked) {
chart["plugins"]=[htmlLegendPlugin];
chart.chart.update();
}
});
where htmlLegendPlugin is the plugin which is given in the link.
New contributor
Sheraz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.