Chartjs-Chart.js plugin datalabels โ€“ formatter- Add space between thousands

3๐Ÿ‘

โœ…

You can use value.toLocaleString() which puts comma between thousands and then replaceAll to replace all commas with space.

        plugins: {
            datalabels: {
                anchor: 'end',
                align: 'right',
                color: '#EA7B30',
                formatter: function(value, context) {
                    return value.toLocaleString().replaceAll(',',' ')
                },              
            }
        }

Leave a comment