Home › forums › Using CanvasJS › How to preserve zeros after decimal point in tooltip?
This topic contains 20 replies, has 3 voices, and was last updated by Vishwas R 2 months ago.
Hi there, pulling figures from a CSV and some values have a zero after the decimal point, but these are lost in the tooltips. So “4.0” in the csv becomes “4” in the tooltip. How can I preserve the decimal point? I tried inserted this in the tooltip but it doesn’t do anything: valueFormatString: “#,###.#0”,
valueFormatString defines how values must be formatted before they appear on axisX, only. To format x-value and y-value that appear in toolTip or indexLabel, you can use xValueFormatString or yValueFormatString respectively.
Priyanka M S
I can’t get this to work, I’m not sure why. I’m going to try to find the previous jsfiddle you were helping with.
Please take a look at this updated jsfiddle.
no, it doesn’t work for me. Please see this updated JSFiddle. Did you do anything else apart from add the lines: yValueFormatString:”##.0″,
In the JSFiddle that you have shared, you are using toolTip contentFormatter where you need to format y-value accordingly – which you can do using formatNumber. Please take a look at this updated JSFiddle.
Hi again, in this solution: https://jsfiddle.net/h41e85dv/, if a value is less than 1, e.g. 0.9, the “0” before the dot does not display. Is there a way to fix this? i.e. The tooltip shows “.9” but it should show “0.9”
When you use “#” in the format-string, it replaces the “#” symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string whereas when you use “0” in format-string it replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string. According to the options / documentation, setting yValueFormatString to “#,##0.0” should let you display 0.9 instead of .9 in toolTip/indexLabel.
Please refer yValueFormatString for all available options.
No, that doesn’t work unfortunately. Any other way?
Correction, it does work, thanks!
Hi, if you change some of the values to ‘null’ in this jsfiddel: https://jsfiddle.net/h41e85dv/ for “country 6′ the line doesn’t connect between the remaining values. How can you make sure, even if there are only two datapoints for one of the lines, that the line still displays? I’ve tried adding “connectNullData: true” but it doesn’t work.
Parsing values from CSV properly for null values should work fine in your case. Please take a look at this updated JSFiddle.
thanks very much!
You must be logged in to reply to this topic.