Can't get Google Charts Axis to format in decimal
Asked Answered
D

2

1

I am trying to set an option for a specific graph in the decimal form. I went through many questions, but I can't seem to figure out why it isn't working for me.

var temp_chart_options = {
   title: 'Temperature',
   hAxis: {title: 'Date',  titleTextStyle: {color: '#262626'}, format:'decimal' },
   vAxis: {minValue: 0, format: 'decimal'},
   keepInBounds: true,
};

temp_chart.draw(temp_data, temp_chart_options);

I tried doing format: 'decimal', or format: { pattern: 'decimal' } and even did temp_chart.draw(data, google.charts.Line.convertOptions(temp_chart_options)); and even looked at these questions:

But none of them seem to work :(

EDIT

Does anyone know how to change the format of the hover?
change the format of the hover

Demanding answered 1/5, 2017 at 13:49 Comment(0)
D
7

The format parameter on your vertical axis needs to specify a proper format pattern. For example, vaxis: {format:'0.00'} will give you a number with two decimal places after it.

Note that Google's documentation is very incomplete about this. They give an example using the presets, and an example of using separators (e.g. '#,###'), but there is no example showing decimal places, nor is there any complete documentation on number format specifiers that I could find. Perhaps it is documented elsewhere, but the page I linked to above ought to at least provide a link to it if so. It does not. I discovered the 0.00 format by experimentation.

Develop answered 1/5, 2017 at 14:9 Comment(1)
What you did work, but I realised that I wasn't trying to change the axis value, it was the hover value. Nonetheless, your answer fixed the problem.Demanding
B
1

As an addition to the accepted answer, I needed to do a currency in GBP with 1000's separators and 2 decimal places.

The given Google 'currency' was unsuitable as it renders the currency symbol in your local currency.

I came up with this:

format: '£#,###.##'

Which could theoretically be used with any currency symbol.

This was the result:

Screenshot of google charts

Banausic answered 22/5, 2019 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.