Google Charts format currency without cent values

Viewed 167

I am currently working on a project that uses the Google Visualization API. I have formatted the values on the y-axis of my chart to display in currency using vAxis: {format: 'currency'} in my options, but I can't figure out how to remove the cent values.

Here is what my chart looks like: Chart

Here are my options:

var options = {
      chartArea: {width: '90%', height: '80%'},
      vAxis: {format: 'currency', ticks: [0, 20000, 40000, 60000]},
      colors: ['#4285f4'],
      legend: {position: 'none'}
    };

On the vAxis it shows marks at $0.00, $20,000.00, $40,000.00, and $60,000.00, but I want it to show marks at $0, $20,000, $40,000, and $60,000.

Thanks in advance for any help.

2 Answers

use a custom format option...

format: '$#,##0'

or you can provide both the value and formatted value in the ticks option...

ticks: [
  {v: 0, f: '$0'},
  {v: 20000, f: '$20,000'},
  {v: 40000, f: '$40,000'},
  {v: 60000, f: '$60,000'}
]

apply toFixed() method on your currencies. You can specify number of decimal places you prefer in brackets. For example variable.toFixed(2).

Related