Home Forums Chart Support Adding the decimal places to the Y-axis

Adding the decimal places to the Y-axis

Viewing 2 posts - 1 through 2 (of 2 total)
  • #41851

    Hi Team,

    I am trying to add decimal places to the y-axis according to the y-axis value. For example, 0-1 –> two decimal places, 1 – 10 –> one decimal place and 10 >= 100 –> no decimal places. I tried to add it but faced few issues. Attached the sample JSFiddle and image for your reference.

    JSFiddle- https://jsfiddle.net/p3vqnc0b/27/
    Image- https://prnt.sc/z1CkAIvHGSzv

    #41854

    @elanchezhiyan,

    You can use labelFormatter function instead of valueFormatString and set the label format using the formatNumber() method. Please take a look at the code snippet below.

    labelFormatter: function(e) {
       if(e.value >= 0 && e.value <= 1)
          return CanvasJS.formatNumber(e.value, "0.00");
       else if (e.value >= 1 && e.value <=10 )
          return CanvasJS.formatNumber(e.value, "0.0");
       else 
          return CanvasJS.formatNumber(e.value, "0");
    }

    Please check this updated JSFiddle for a working example.


    Thangaraj Raman
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.