Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js number format

I went over the Chart.js documentation and did not find anything on number formatting ie) 1,000.02 from number format "#,###.00"

I also did some basic tests and it seems charts do not accept non-numeric text for its values

Has anyone found a way to get values formatted to have thousands separator and a fixed number of decimal places? I would like to have the axis values and values in the chart formatted.

like image 876
Ronald Avatar asked Sep 17 '14 01:09

Ronald


People also ask

Which is better D3 or chart js?

Chart. js provides a selection of ready to go charts which can be styled and configured while D3 offers building blocks which are combined to create virtually any data visualisation.

Is Chart js any good?

js. Chart. js is a popular open source JavaScript charting library. It has 53.7k stars on GitHub and a good ecosystem with wrappers for Vue, React, Ember and other frameworks.


1 Answers

Put tooltips in 'option' like this:

options: {   tooltips: {       callbacks: {           label: function(tooltipItem, data) {               return tooltipItem.yLabel.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');           }       }   } } 

Reference from https://github.com/chartjs/Chart.js/pull/160.

like image 169
Irfan Hafid Nugroho Avatar answered Oct 14 '22 07:10

Irfan Hafid Nugroho