Chartjs-ChartJS unable to register global plugin

0๐Ÿ‘

โœ…

By reading the documentation better a unique id must be configured for each registered plugin.

Plugins must define a unique id in order to be configurable.

So i just added the id in my code

Chart.register({
    id: 'no_data_label',
    afterDraw: (chart, args, options) => {
        const data = chart.data.datasets[0].data;
        if (data.length === 0) {
            // No data is present
            console.log(chart)
            const current = chart.ctx;
            const width = chart.width;
            const height = chart.height
            chart.clear();

            current.save();
            current.textAlign = 'center';
            current.textBaseline = 'middle';
            current.font = "16px normal 'Helvetica Nueue'";
            current.fillText('Nessun dato disponibile', width / 2, height / 2);
            current.fontColor = "#828282";
            current.restore();
        }
    }
});

Leave a comment