7

I'm using Google Gauges and would like to add a % sign after the value in the gauge. My values display with fine without the percent symbol (whole numbers 0 - 100), but when I start trying to add the percent symbol things get wonky.

Here's what I've tried

// Format the data to include % symbol
var formatter = new google.visualization.NumberFormat(
    {suffix: '\u0025'}
    //{suffix: '%'}
    //{pattern: '#%'}

);

All three attempts display the correct visualization, but for the actual value text I get varying results.

Using either suffix method it adds two decimal places:

6 => 6.00%

26 => 26.00%

and so on

Using the pattern method it multiples the value by 100

6 => 600%

26 => 2600%

and so on

Any clue on how to simply display the value along with a percent symbol?

Smeegs
  • 9,151
  • 5
  • 42
  • 78
dscl
  • 1,616
  • 7
  • 28
  • 48
  • Use `var formatter = new google.visualization.NumberFormat({pattern: "#'%'"});`. The quotes around the `%` tell the formatter to treat it as a string and not the percent modifier. – asgallant Mar 27 '14 at 18:17

1 Answers1

10

It's simpler than all that. If you just make a number formatter, specifying the pattern, and the suffix, you're all set:

http://jsfiddle.net/fHnnn/

Jeremy Faller
  • 1,394
  • 11
  • 9