Issue with int numbers using chart.js

70 Views Asked by At

So, I'm exploring this code:

http://jsfiddle.net/UNs9J/5611/

$(function(){

 $("#doughnutChart").drawDoughnutChart([
    { title: "Tokyo",         value : 120,  color: "#2C3E50" },
    { title: "San Francisco", value:  80,   color: "#FC4349" },
    { title: "New York",      value:  70,   color: "#6DBCDB" },
    { title: "London",        value : 50,   color: "#F7E248" },
    { title: "Sydney",        value : 40,   color: "#D7DADB" },
    { title: "Berlin",        value : 20,   color: "#FFF" }
  ]);
});

And I cant find how can I show a int number in the total. I Want to display 380 instead 380.0

Can anyone help me?

Thanks in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

Apparently there is not option for changing this out of the box. You'll have to change the source.

Simply change:

function drawDoughnutText(animationDecimal, segmentTotal) {
   $summaryNumber
      .css({opacity: animationDecimal})
      .text((segmentTotal * animationDecimal).toFixed(1));
}

to

function drawDoughnutText(animationDecimal, segmentTotal) {
   $summaryNumber
      .css({opacity: animationDecimal})
      .text((segmentTotal * animationDecimal).toFixed(0));
}

Bear in mind the total will be always an integer, even though it sums up to a float number.

0
On

On line 216 of the jsfiddle change the toFixed parameter to 0

.text((segmentTotal * animationDecimal).toFixed(0));