Home Forums Chart Support Group separator only for numbers greater than 9999

Group separator only for numbers greater than 9999

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

    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 6 years, 5 months ago by Michaelp. Reason: Found a typo
    #21013

    Michael,

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


    Vishwas R
    Team CanvasJS

    #21054

    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

    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

    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.