Home forums Using CanvasJS Group separator only for numbers greater than 9999

This topic contains 4 replies, has 2 voices, and was last updated by  Michaelp 4 months, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21009

    Michaelp
    Member

    Hi everyone,

    Is there a way for me to format numbers so numbers greater than 9999 use a comma to separate them (e.g. 10,000) but numbers less than 10,000 do not use a comma (e.g. 1000)?

    Kind regards,

    Michael

    • This topic was modified 4 months, 2 weeks ago by  Michaelp. Reason: Found a typo
    #21013

    Vishwas R
    Keymaster

    Michael,

    You can achieve this with the help of axis labelFormatter and formatNumber(). Please take a look this jsfiddle.


    Vishwas R
    Team CanvasJS

    #21054

    Michaelp
    Member

    Thanks Vishwas.

    I note that the y value in the tooltip still has a comma for numbers equal to or less than 9999.

    Is there any easy way of replicating the labelFormatter in the tooltip without rebuilding it through contentFormatter? E.g can you use the labelFormatter for a datapoint’s yValueFormatString attribute?

    Kind regards,

    Michael

    #21085

    Vishwas R
    Keymaster

    Michael,

    Sorry to inform you that its not possible to avoid using contentFormatter in this scenario. yValueFormatString is a property of dataSeries that accepts string whereas labelFormatter and contentFormatter are methods of axis and toolTip respectively.

    However you can reduce the number of lines of code using ternary operator. Please take a look at this updated JSFiddle.


    Vishwas R
    Team CanvasJS

    #21109

    Michaelp
    Member

    Thanks Vishwas. That is very helpful.

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

You must be logged in to reply to this topic.