Precision of floating point values in axes & mouseovers

1,392 views
Skip to first unread message

Wells Oliver

unread,
Sep 6, 2011, 3:00:08 PM9/6/11
to Google Visualization API
Hey, is it possible to control the precision of floating point values
in the chart axes and mouseover tool tips? I'd like three full values
and no leading zeroes, but I'm not sure if this can be done.

Thank you.

asgallant

unread,
Sep 6, 2011, 3:20:39 PM9/6/11
to google-visua...@googlegroups.com
If you want a given level of precision (ie, 3 decimal places), use the Number Format (http://code.google.com/apis/chart/interactive/docs/reference.html#numberformatter) on columns to set your precision for the tooltips, and use the h/vaxis.format option to set the precision for the axes (ex, for bar charts: http://code.google.com/apis/chart/interactive/docs/gallery/barchart.html#Configuration_Options).

If you always want to display the same number of digits, regardless of the precision of the digits (ie, 3 digits in any place: .123, 3.45, 67.8), then you can write a function that takes your data as an input and creates a formatted string version of each value with the appropriate number of digits.  Pass the formatted value back to the dataTable object with the #setFormattedValue (http://code.google.com/apis/chart/interactive/docs/reference.html#DataTable) method (or process your data before creating the dataTable object and build the dataTable by passing the {v: value, f: 'formatted value'} object to each cell).  The axis values are auto-calculated and aside from using the axis format option there is nothing you can do to control the precision.

Wells Oliver

unread,
Sep 7, 2011, 1:34:21 PM9/7/11
to Google Visualization API
Is there a way to use the '@@' feature of the ICU decimal formatting?
I want three decimal places and no leading zeroes if less than 1, and
I can't seem to get that using the format option of the hAxis.

On Sep 6, 12:20 pm, asgallant <drew_gall...@abtassoc.com> wrote:
> If you want a given level of precision (ie, 3 decimal places), use the
> Number Format (http://code.google.com/apis/chart/interactive/docs/reference.html#num...)
> on columns to set your precision for the tooltips, and use the
> h/vaxis.format option to set the precision for the axes (ex, for bar
> charts:http://code.google.com/apis/chart/interactive/docs/gallery/barchart.h...
> ).
>
> If you always want to display the same number of digits, regardless of the
> precision of the digits (ie, 3 digits in any place: .123, 3.45, 67.8), then
> you can write a function that takes your data as an input and creates a
> formatted string version of each value with the appropriate number of
> digits.  Pass the formatted value back to the dataTable object with the
> #setFormattedValue (http://code.google.com/apis/chart/interactive/docs/reference.html#Dat...) method

asgallant

unread,
Sep 7, 2011, 1:57:10 PM9/7/11
to google-visua...@googlegroups.com
After looking into the ICU patterns, you should be able to control significant digits using '@', but ICU specifies the leading zero for decimal values between -1 and 1; I haven't found any option that removes it, but admittedly, my knowledge if ICU formatting is very limited.
Reply all
Reply to author
Forward
0 new messages