Displaying currency in Google chart API

There's a format for specifying both the raw value and formatted value for a cell: when loading the value into the chart, rather than, e.g. addRow(['2012-08-31, 4]); it would be addRow(['2012-08-31', {v: 4, f: '$4.00'}]); More examples of that syntax are sprinkled through the docs but I couldn't find a good place to link to it. It shouldn't be too hard to change the method by which the $data object from your example is generated to include that formatting, but there are other formatting options too.

If you'd rather define that formatting in the JS for whatever reason, you can use a NumberFormatter.


This is perfect format to Brazilian currency:

  var formatter = new google.visualization.NumberFormat({decimalSymbol: ',',groupingSymbol: '.', negativeColor: 'red', negativeParens: true, prefix: 'R$ '});
  formatter.format(data, 1);

Works fine whit dollar also, just change R$ to $

10500.5 stay 10.500,50, more prefix

10500 stay 10.500,00, more prefix

Tags:

Php

Api