简体   繁体   中英

How do I append a percent sign to my chart values?

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'
    }
};

jsFiddle : My full code

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...

Edit

You've actually been pretty close to solution :) you should use suffix instead of pattern . I updated your fiddle: http://jsfiddle.net/jr59x/1/

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: "##,##'%" ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM