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

Community
  • 1
  • 1
dsomel21
  • 576
  • 2
  • 8
  • 27

2 Answers2

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.

Jeff Loughlin
  • 4,134
  • 2
  • 30
  • 47
  • 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. – dsomel21 May 01 '17 at 14:49
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

Pat Dobson
  • 3,249
  • 2
  • 19
  • 32