[Chartjs]-How to create a variable for chart js datalabel plugin formatter

2👍

plugins.datalabels.formatter should be set to a function. You are setting it to an object. Change your definition so it doesn’t include the leading { and trailing }:

var datalabels_format_sanssymb = function (value) {
    if (value >= 1000000000 || value <= -1000000000) {
        return (value / 1000000000).toFixed(1).replace(/\.0$/, '');
    }
    if (value >= 1000000 || value <= -1000000) {
        return (value / 1000000).toFixed(1).replace(/\.0$/, '');
    }
    if (value >= 1000 || value <= -1000) {
        return (value / 1000).toFixed(1).replace(/\.0$/, '');
    }
    return value;
}

See the plugin documentation for examples.

Leave a comment