[Chartjs]-Displaying Currency symbol in Chart.JS 4 within Blazor

0👍

Since v3 the tooltip is located under plugins in options: here

This is how it looks in javaScript:

options:{        
    ...
    plugins: {
        tooltip: {
            callbacks: {
                label: function (context) {
                    if (context.parsed.y !== null) {
                        return context.dataset.label + ": " +
                            new Intl.NumberFormat('de-DE', {
                                style: 'currency',
                                currency: 'EUR'
                            }).format(context.parsed.y);
                    }
                    return "";
                }
            }
        }
    }
    ...
}

For the y-axis you also can use a callback:

options:{
    ...
    scales: {
        y: {          
            ticks: {
                callback: function (value, index, ticks) {
                    return new Intl.NumberFormat('de-DE', {
                        style: 'currency',
                        currency: 'EUR'
                    }).format(value);
                }
            }
        }
    }
    ...
}

Attention, note that it is called "tooltip," not "tooltips"!

Leave a comment