Reputation: 3
I would like to know, how can I append a percent sign (%) to the numbers inside my chart? I have already the numbers, I just want to have the symbol '%' after the numbers.
My options:
var options = {
title: '',
format: '#,#%',
fontSize: 12,
hAxis: {
suffix: '%',
ticks: [
{v: 0,f: '0%'},
{v: 25,f: '25%'},
{v: 50,f: '50%'},
{v: 75,f: '75%'},
{v: 100,f: '100%'}
]
}, //Baixo
vAxis: {
title: '',
fontSize: 16,
format: '#%',
maxValue: 100
},
isStacked: 'true',
color: '#000',
colors: ['#4747D1', '#C2C2F0', '#B9CAFF', '#FF9999', '#A32900'],
legend: {
position: 'top'
}
};
Upvotes: 0
Views: 170
Reputation: 26340
Change the pattern
in your NumberFormat:
var formatter = new google.visualization.NumberFormat({pattern: '##,##\'%'});
The %
character converts the value to a percentage (so 0.5
becomes 50%
), which isn't what you want, so you have to escape it with '%
('
is the escape character, which must be escaped, since the string uses single-quotes; alternatively you can use double-quotes for the string: "##,##'%"
).
Upvotes: 1
Reputation: 1889
I don't know if I understand you correctly, but...percent is just a one hundredth part of something, so you must divide your 'something' by 100...
You've actually been pretty close to solution :) you should use suffix
instead of pattern
.
I updated your fiddle:
http://jsfiddle.net/jr59x/1/
Upvotes: 1