This is a migrated thread and some comments may be shown as answers.

Unexpected single decimal place on value axis when formatting is set to percentage.

5 Answers 355 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 24 Nov 2015, 11:42 AM
When I pass the following chart to kendo the value 55% on the value axis is presented as 55.0% instead of as a whole number, this problem happens only at 55% all the other values are shown as whole numbers. Why is Kendo forcing this value have a decimal place of 1? Many thanks,

Peter

``` $scope.chart:  {
  "seriesDefaults": {
    "multiseries": false,
    "type": "column"
  },
  "title": {
    "text": null,
    "align": "left"
  },
  "legend": {
    "position": "top",
    "visible": true
  },
  "series": [
    {
      "color": "#83c774",
      "data": [
        {
          "value": 1.7985
        },
        {
          "value": 101
        },
        {
          "value": 81
        }
      ],
      "name": "Nov 2015",
      "padding": 40
    },
    {
      "color": "#8ed4c4",
      "data": [
        {
          "value": 27
        },
        {
          "value": 121
        },
        {
          "value": 71
        }
      ],
      "name": "Dec 2015",
      "padding": 40
    }
  ],
  "categoryAxis": {
    "categories": [
      "small pancakes",
      "rainbow",
      "Spaghetti Colours"
    ],
    "labels": {
      "rotation": 315
    }
  },
  "valueAxis": {
    "min": 0.5,
    "max": 0.9,
    "title": {
      "text": null
    },
    "labels": {
      "format": "{0:#.#%}"
    }
  },
  "tooltip": {
    "format": "{0:#.#%}",
    "visible": true
  }
} ```

5 Answers, 1 is accepted

Sort by
0
EZ
Top achievements
Rank 2
answered on 24 Nov 2015, 03:24 PM
I don't know why it is doing that, but if you don't want decimals, chage your format to "{0:#%}"
0
Peter
Top achievements
Rank 1
answered on 24 Nov 2015, 03:34 PM
Hello Erik, thanks for getting back to me! :) I've actually already implemented a solution for the valueAxis were if the numbers are going to be whole they are forced to have no decimals using the format you've suggested. The problem however is using this format for tooltips, my client isn't happy with decimal places showing 0 on the tool tips. They want everything rounded to 1 decimal place unless it's a whole number in which case it's to display as a whole number.
0
EZ
Top achievements
Rank 2
answered on 24 Nov 2015, 03:39 PM
For me the tooltips are acting as you desire:  http://dojo.telerik.com/@ezanker/AXiBA
0
Peter
Top achievements
Rank 1
answered on 24 Nov 2015, 03:45 PM
Sorry this is my bad, You're correct is displaying as expected with the data provided, if you change one of the series items to equal ` {"value": 2.70020} ` you'll see the 0 decimal :)
0
EZ
Top achievements
Rank 2
answered on 24 Nov 2015, 07:04 PM

You could work around this with the template object and a function to trim the '.0':

function FormatPercent(val){
  var p = kendo.toString(val * 100, 'n1');
  if (p.indexOf('.0') > 0) {
    p = kendo.toString(val * 100, 'n0');
  }
  return p;
}
 

 

"tooltip": {
  "template": "#= FormatPercent(value)  #%",
  "visible": true
}

 

 

Updated DEMO

Tags
Charts
Asked by
Peter
Top achievements
Rank 1
Answers by
EZ
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Share this question
or