Google Chart veritcal axis with percentage sign

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

Im using google chart api to show line chart in my application, in that chart now i want to show the vertical axis values with percentage sign. for that i tried the following option

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

as mentioned in

How do you set percentage in Google Visualization Chart API?

by 'B Seven'

when using this method, the vertical axis values got multiplied by 100. i.e instead of '12%' - im getting 1200% in vaxis!!!!

i have checked in https://developers.google.com documents also, i cant find any approach to do this.

Is there any alternate to show percentage sign in vaxis.

回答1:

Escaping the percentage sign in format works for me.

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

This shows Y axis labels with percentage sign without any data update as I expected.



回答2:

Problem is that there is no data type percentage but only number, date... Google docs describes hAxis.format and vAxis.format as:

For number axis labels, this is a subset of the decimal formatting ICU pattern set. For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.

And ICU pattern set states:

%   Prefix or suffix    Yes Multiply by 100 and show as percentage 

So, it seems that the only option is to divide values with 100 on server or client side.



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