简体   繁体   中英

Change Y Axis Value to Integer (no decimal values) in AmCharts

I have a chart in AmCharts that reflects integer values; as such I want the value in the Y Axis to also be integers however they are showing up as floating point. I have read through documentation and found reference to: numberFormatter with the following syntax:

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

Changing the precision does not seem to have an impact. I've seen suggestions at setting it to 0 would work for removing the value after the decimal but it does not. I have also read that setting precision to -1 inhibits rounding which confuses me as to what precision is used for.

I am using AmCharts version 2.9.3 . I have found that there is a bug where numberFormatter is ignored in this version (pre 2.11) when usePrefixes was set to true however that is not the case.

I have found references to a parameter called: digits_after_decimal

However the references I found were for much older versions of AmCharts and the reference was for this parameter in a config file; and I do not see a reference for this in my version.

I have done quite a bit of research and am looking for any pointers as to what I am doing wrong as I know this is simply a misunderstanding of the API. I have also been toying with a JSFiddle example from AmCharts site:

http://jsfiddle.net/amcharts/zu9nW/

I have found a solution. There are custom sections for updating qualities of both the y and x axis; in this case for the y axis, adding the following will represent only integers for the value column which on my graph was the y axis.

var valuesAxis = new AmCharts.ValueAxis();

valuesAxis.integersOnly = true;

对于amCharts v4,它将是:

valueAxis.maxPrecision = 0;

In my code for the valueAxes object I have added integersOnly property true . It is working fine for me.

"valueAxes": [ {
    "gridColor": "#FFFFFF",
    "gridAlpha": 0.2,
    "dashLength": 0,
    "title": "Response Count",
    "autoGridCount": false,
    "gridCount": 5,
    'integersOnly':true
  },
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM