简体   繁体   English

将AmCharts中的Y轴值更改为整数(无小数)

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

I have a chart in AmCharts that reflects integer values; 我在AmCharts中有一张图表,可以反映整数值。 as such I want the value in the Y Axis to also be integers however they are showing up as floating point. 因此,我希望Y轴上的值也为整数,但是它们显示为浮点数。 I have read through documentation and found reference to: numberFormatter with the following syntax: 我已通读文档,并使用以下语法找到了对numberFormatter的引用:

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. 我看到过将其设置为0的建议,可以删除小数点后的值,但不能删除。 I have also read that setting precision to -1 inhibits rounding which confuses me as to what precision is used for. 我还读到将精度设置为-1会禁止舍入,这使我对精度使用什么感到困惑。

I am using AmCharts version 2.9.3 . 我正在使用AmCharts 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. 我发现有一个错误,当usePrefixes设置为true时,在此版本(2.11之前)中,numberFormatter被忽略,但事实并非如此。

I have found references to a parameter called: digits_after_decimal 我发现了对一个名为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; 但是,我找到的引用是针对AmCharts的较旧版本,而引用是针对配置文件中的此参数的; 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. 我已经做了很多研究,并且正在寻找关于我做错了什么的指针,因为我知道这仅仅是对API的误解。 I have also been toying with a JSFiddle example from AmCharts site: 我还一直在玩AmCharts网站上的JSFiddle示例:

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

I have found a solution. 我找到了解决方案。 There are custom sections for updating qualities of both the y and x axis; 有一些自定义部分,用于更新y和x轴的质量。 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. 在这种情况下,对于y轴,添加以下内容将只代表值列的整数,在我的图表上该值列是y轴。

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 . 在我的valueAxes对象的代码中,我添加了integersOnly属性true It is working fine for me. 对我来说很好。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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