Home forums Using CanvasJS How to reduce number of 0 on Y axis?

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #29028

    Good afternoon,

    I am displaying data from the database onto the graph. Values that I am plotting on Y axis are Watts. The small problem is that on the graph, my Y values are like this:

    600,000,000,000
    500,000,000,000
    400,000,000,000
    ...

    So my question is, is there a function, which would allow me to replace those extra 0s’ into something like this:

    600T Watts
    500T Watts
    400T Watts
    ...

    I do apologies if this question was already asked, I have tried finding this answer here already, but I couldn’t find anything similar.

    Thank you kindly in advance.
    Best wishes,
    Saul

    #29031

    Please Ignore this. It has been resolved using this function:

    function addSymbols(e) {
                    var suffixes = ["", "K", "M", "B"];
    
                    var order = Math.max(Math.floor(Math.log(e.value) / Math.log(1000)), 0);
                    if (order > suffixes.length - 1)
                        order = suffixes.length - 1;
    
                    var suffix = suffixes[order];
                    return CanvasJS.formatNumber(e.value / Math.pow(1000, order)) + suffix;
                }

    and declaring it in Y axis.

    Thank you.

    #29049

    Saul,

    Glad that you figured it out :)


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.