Chart.js: Thousands seperator

Created on 2 Jul 2014  路  9Comments  路  Source: chartjs/Chart.js

How can I implement the thousands separator shown last year into the latest build? Thanks!

Most helpful comment

I'm using Angular Chart.js (Anyway; it's Chart.js) here is how I thousand separate the tooltip number:

$scope.chartOption = {
            tooltips: {
                enabled: true,

                callbacks: {
                    label: function (tooltipItems, data) {
                        return data.datasets[tooltipItems.datasetIndex].label + ' : ' + tooltipItems.yLabel.toLocaleString();
                    }
                }
            }
          }

All 9 comments

You can vote for #438 and then use the template field as a function that will produce the necessary output.

:+1: #438 is merged and released so you should be able to do this.

Something like this should do the trick:

scaleLabel: function(label){return label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");}

Is that possible to have a thousands separator for the tooltips as well?

// String - Template string for single tooltips
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",

// String - Template string for single tooltips
multiTooltipTemplate: "<%= value %>",

BTW: The comment above multiTooltipTemplate says: "Template string for single tooltips" here: http://www.chartjs.org/docs/#getting-started-global-chart-configuration

got it:

Chart.defaults.global.multiTooltipTemplate = function(label){
    return label.datasetLabel + ': ' + label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
};

here's the final example including thousands separators for tooltips: http://jsbin.com/jihadu/1/edit?html,js,output

+1

+1

I'm using Angular Chart.js (Anyway; it's Chart.js) here is how I thousand separate the tooltip number:

$scope.chartOption = {
            tooltips: {
                enabled: true,

                callbacks: {
                    label: function (tooltipItems, data) {
                        return data.datasets[tooltipItems.datasetIndex].label + ' : ' + tooltipItems.yLabel.toLocaleString();
                    }
                }
            }
          }

got it:

Chart.defaults.global.multiTooltipTemplate = function(label){
return label.datasetLabel + ': ' + label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
};

Only your solution works for me, thanks dude

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriantombu picture adriantombu  路  3Comments

bytesnz picture bytesnz  路  3Comments

JAIOMP picture JAIOMP  路  3Comments

SylarRuby picture SylarRuby  路  3Comments

akashrajkn picture akashrajkn  路  3Comments