向Google量表添加%符号 [英] Adding a % sign to Google Gauges

查看:74
本文介绍了向Google量表添加%符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Gauges,并希望在量表中的值后面添加%符号。我的数值显示没有百分比符号(整数0-100),但是当我开始尝试添加百分比符号的时候,事情会变得糟糕。



这是我'已尝试

  //格式化数据以包含%符号
var formatter = new google.visualization.NumberFormat(
{后缀:'\\\%'}
// {后缀:'%'}
// {pattern:'#%'}

);

所有三次尝试都显示正确的可视化效果,但对于实际值文本,我会得到不同的结果。 p>

使用后缀方法可以增加两位小数:

6 => 6.00%



26 => 26.00%


等等



使用模式方法它的价值倍数为100美元b
$ b 6 => 600%

<26> 26 => 2600%



等等



有关如何简单显示数值以及百分号的任何线索?

解决方案

它比所有这些都更简单。如果你只是创建一个数字格式化程序,指定模式后缀,你就全部设置:



http://jsfiddle.net/fHnnn/


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?

解决方案

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/

这篇关于向Google量表添加%符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆