AmCharts - Decimal Rounding of the Mean

3

I am working with AmCharts. My chart is fully functional, and I want the median value to show. Here I put my code:

"graphs": 
 [
   {
     "title": "Total Open Ratio %",
     "valueField": "def",
     "type": "line",
     "fillAlphas": 0.2,
     "legendPeriodValueText": "Average: [[value.average]] %",
     "legendValueText": "[[value]] %",
     "lineColor" : "#26a69a",
     "lineColorField": "lineColor",
     "balloonText": "<b>[[title]]</b><br>[[value]] %",                    
     "lineThickness": 1,
   }
 ],

Reference: link

Everything works perfectly, but the median value is too long: Does anyone know how to use only the first two decimals as: 19.41% instead of 19.41051724137931%?

    
asked by AConti 25.01.2016 в 13:08
source

2 answers

2

Depends on the type of graph you use, but AMChart (the abstract that everyone inherits and can not be Instanced) has two properties that will help you:

numberFormatter

Object  {precision:-1, decimalSeparator:'.', thousandsSeparator:','}    
  

Object to format numbers. Precision = -1 means that the values are not going to be rounded

percentFormatter

Object  {precision:2, decimalSeparator:'.', thousandsSeparator:','} 
  

Object with precision , decimalSeparator and separadorDeMiles previously defined to format percentages.

That yes, I have not been able to find practical examples where they explain their use ...

    
answered by 25.01.2016 / 14:00
source
1

Thanks for your contributions. I add how I fixed it. I would have used percentFormatter but if I was not passing it as a percentage, it would be better for me.

var chart = AmCharts.makeChart( "chart_opens_def", {
 "type": "serial",
        [...]
         "numberFormatter": 
        {
            "precision": 2,
            "decimalSeparator": ".",
            "thousandsSeparator": ","
        },   
"graphs": 
        [
          {
            "title": "Total Open Ratio %",
            "valueField": "def",
            "type": "line",
            "fillAlphas": 0.2,
            "legendPeriodValueText": "Average: [[value.average]] %",
            "legendValueText": "[[value]]",
            "lineColor" : "#26a69a",
            "lineColorField": "lineColor",
            "balloonText": "<b>[[title]]</b><br>[[value]]",                    
            "lineThickness": 1,
          }
       ],
       [...]

Thanks !!

    
answered by 26.01.2016 в 10:17