Home › forums › Using CanvasJS › Group separator only for numbers greater than 9999
Tagged: format, group separator, number, separator
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)?
You can achieve this with the help of axis labelFormatter and formatNumber(). Please take a look this jsfiddle.
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?
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.
Thanks Vishwas. That is very helpful.
You must be logged in to reply to this topic.