Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number format with Amcharts Javascript

Tags:

amcharts

Amchart give me amazing graphics into HTML but...

How to format the number axis? Currently it shows me 65,000 and I need value like 65000. No commas!

Thanks!

like image 519
orafaelreis Avatar asked Oct 18 '12 14:10

orafaelreis


3 Answers

I solved the problem!

Into AmCharts.ready(function(){ put

chart.numberFormatter = {
  precision:-1,decimalSeparator:",",thousandsSeparator:""
};

All Number Format happens there!


var chart = AmCharts.makeChart("chartdiv", {
        [...]
        "numberFormatter": {
            "precision": -1,
            "decimalSeparator": ",",
            "thousandsSeparator": ""
        }
    });
like image 144
orafaelreis Avatar answered Nov 02 '22 03:11

orafaelreis


If you need to format definite number:

var formatted = AmCharts.formatNumber(number, 
{
     precision: chart.precision,
     decimalSeparator: chart.decimalSeparator,
     thousandsSeparator: chart.thousandsSeparator
}, 2);

formatNumber(number, formatter, zeroCount)

Returns string formatter with the provided settings. Formatter is an object with precision, decimalSeparator and thousandsSeparator defined, like: {precision: 2, decimalSeparator: '.', thousandsSeparator: ','}; If you don't need to adjust precision set it to -1. zeroCount defines how many zeros should be added after comma (useful when formatting currencies).

like image 23
Zvezdochka Avatar answered Nov 02 '22 03:11

Zvezdochka


Put this, it will remove, from thousands (refer docs)

"numberFormatter": {precision:-1, decimalSeparator:',', thousandsSeparator:''},
like image 32
Shobha Avatar answered Nov 02 '22 01:11

Shobha