How do you set percentage in Google Visualization Chart API?

冷暖自知 提交于 2019-12-05 09:47:16

问题


How do you set the vertical axis to display percent such as 25%, 50%, 75%, 100%?


回答1:


var options = {
        title: 'Chart Title',
        vAxis: {
            minValue: 0,
            maxValue: 100,
            format: '#\'%\''
        } 
    };

Try escaping the % sign. I've used this to just append the % sign in the y axis.




回答2:


chart.draw(data, {vAxis: {format:'#%'} } );

To get comma for thousands, use {format:'#,###%'}.

See http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html




回答3:


Using bar charts, I found my results haphazard and I got to consistency by doing the following: 1. In your data column, set a value of 100, even if you add a dummy value of 100. 2. Select all the numeric cells in the column and format them using Format, Number, Normal 3. Now format them to % using Format, Number, Percent Rounded

Your graph should now show 100% on the vertical scale and if you have a dummy value for 100% you will want to hide it, so you can either format it by clicking on it in the graph and changing the color (but this doesn't seem to work every time) or go to Advanced Edit, Customize, Columns, select your column name (from the graphic legend) and set the bar color to None or whatever your background color is.

Good luck.



来源:https://stackoverflow.com/questions/6478364/how-do-you-set-percentage-in-google-visualization-chart-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!