如何格式化在谷歌API的折线图号? [英] How to format numbers in Google API Linechart?

查看:210
本文介绍了如何格式化在谷歌API的折线图号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的格式在轴上的数字,当你将鼠标悬停在折线图显示的号码。

I need to format the numbers in the axis and the numbers that appear when you hover your mouse over the line chart.

推荐答案

有涉及到两个步骤。第一步是找出你应该使用什么样的模式;第二步骤是将在适当的位置的图案中的code。为了让这个帖子更漂亮,我会告诉你2步,然后步骤1。

There are two steps involved. The first step is to find out what pattern you should use; the second step is to put the pattern in the proper place in your code. To make this post more beautiful, I show you step 2 and then step 1.

这里的code:

var options = {
        hAxis: {format:'###,###'}
        vAxis: {title: 'Time', format:'0.0E00'},
    };
    var formatter1 = new google.visualization.NumberFormat({pattern:'###,###'});
    formatter1.format(dataTable, 0);
    var formatter2 = new google.visualization.NumberFormat({pattern:'0.0E00'});
    formatter2.format(dataTable, 1);
    var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
    fchartvar.draw(dataTable, options);

vAxis是:{title:时间,格式为:0.0E00'} 格式在垂直轴上标签

这格式的数字可以看到,当你将鼠标悬停在点线图上:

This formats the numbers you see when you hover over points on the line chart:

var formatter1 = new google.visualization.NumberFormat({pattern:'0.0E00'});
formatter1.format(dataTable, 1);

请注意如何(dataTable中,0)格式化hAxis信息,而(dataTable中,1)格式化vAxis信息(同样,你看,当你将鼠标悬停在点线图上)。

Note how (dataTable,0) formats the hAxis information while (dataTable,1) formats the vAxis information (again, which you see when you hover over the points on the line chart).

code的最后两行:

The last two lines of code:

var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
fchartvar.draw(dataTable, options);

对于你们两个跟自己的图表进行比较。替换 fchartvar 的dataTable fchart 在使用的名称您code。如果您使用的是折线图以外的东西,代替线型图与您正在使用的图表。

are for you two compare with your own chart. Replace fchartvar,dataTable and fchart by the names used in your code. If you're using something other than line chart, replace LineChart with the chart you're using.

0.0E00 的一个例子是转动 1,234 1.2E03

An example of 0.0E00 is turning 1,234 into 1.2E03.

的NumberFormat支持以下选项中传递给构造函数:(来源:谷歌的NumberFormat文档

NumberFormat supports the following options, passed in to the constructor: (source: Google NumberFormat documentation)

decimalSymbol

decimalSymbol


  • 一个字符作为小数点标记使用。默认值是一个点(。)。

参数fractionDigits

fractionDigits


  • 一个数字,指定多少位数字小数点后显示。该
    默认值为2.如果您指定更多的数字比数字包含,它
    将显示值为零的较小值。截断值将是
    圆角(5四舍五入)。

groupingSymbol

groupingSymbol


  • 字符被用来组数字的小数点左边
    到三套。默认值是一个逗号(,)。

negativeColor

negativeColor


  • 的文本颜色为负值。没有默认值。值可以是
    任何可接受的HTML颜色值,如红或#FF0000。

negativeParens

negativeParens


  • boolean值,其中true表示负值应
    用括号包围。默认值为true。

模式


  • 一个格式字符串。如果提供,所有其他选项都被忽略,除了
    negativeColor。

  • A format string. When provided, all other options are ignored, except negativeColor.

格式字符串是 ICU模式集 的一个子集。例如,
{图案:#,###%'}将导致输出值1000%,750%,和
50%的值10,7.5和0.5。

The format string is a subset of the ICU pattern set. For instance, {pattern:'#,###%'} will result in output values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.

preFIX


  • 的字符串preFIX的值,例如$。

后缀


  • 的字符串后缀的值,例如%。

你可能已经从上面的谷歌文档的NumberFormat注意到,您可以了解从ICU DecimalFormat的参考格式化数字的更多详细信息。下面是一些从 ICU DecimalFormat的参考中的最重要的信息(这是在的'中间'网页):

As you might have noticed from the Google NumberFormat documentation above, you can find out more detailed information about formatting the numbers from the ICU DecimalFormat Reference. Here is some of the most important information from the ICU DecimalFormat Reference (it's in the 'middle' of the webpage):

一个DecimalFormat模式包含一个正负子模式,例如#,## 0.00;(#,## 0.00)。每个子模式有一个preFIX,数字部分和后缀。如果没有明确的负数子模式,负子模式是pfixed到正子模式的本地化的减号$ P $。也就是说,0.00单独是相当于0.00; -0.00。如果有一个明确的负子模式,它仅用于指定负preFIX和后缀;的数字,最小位数,和其他特征的数目在负子模式将被忽略。这意味着,#,## 0.0#;(#)具有precisely相同的结果。#,## 0.0#;(#,## 0.0#)

A DecimalFormat pattern contains a postive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, a numeric part, and a suffix. If there is no explicit negative subpattern, the negative subpattern is the localized minus sign prefixed to the positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are ignored in the negative subpattern. That means that "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".

在prefixes,后缀和各种用于无穷大,数字,千位分隔符,小数点分隔符号等可以设置为任意值,他们会在格式化期间正确显示。然而,必须注意的符号和字符串不冲突,或解析将不可靠。例如,无论是正和负prefixes或后缀必须是不同的用于解析(),以便能够从负值区分阳性。另一个例子是,小数点分隔符和千位分隔符应该是不同的字符,或对其进行解析是不可能的。

The prefixes, suffixes, and various symbols used for infinity, digits, thousands separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, either the positive and negative prefixes or the suffixes must be distinct for parse() to be able to distinguish positive from negative values. Another example is that the decimal separator and thousands separator should be distinct characters, or parsing will be impossible.

分组分隔符分隔整数位集群,使大量更清晰的字符。它常用于成千上万,但在某些语言环境,它用于分隔万位。分组大小是分组隔板之间的数字,如3亿或41 0000 0000的号码。实际上有两种不同的分组大小:一个用于至少显著整数位,主分组大小,和一个用于所有其他次要分组大小。在大多数的区域设置这些是相同的,但有时却是不同的。例如,如果主分组间隔为3,二次为2,则这对应于模式#,##,## 0,并且数量123456789被格式化为12,34,56,789。如果一个图案包含多个分组分离器,最后一个和整数的端部之间的间隔限定了主分组大小,以及最后两个之间的间隔限定了次级分组大小。所有其他被忽略,因此#,##,###,####==###,###,####==##,####,# ###。

The grouping separator is a character that separates clusters of integer digits to make large numbers more legible. It commonly used for thousands, but in some locales it separates ten-thousands. The grouping size is the number of digits between the grouping separators, such as 3 for "100,000,000" or 4 for "1 0000 0000". There are actually two different grouping sizes: One used for the least significant integer digits, the primary grouping size, and one used for all others, the secondary grouping size. In most locales these are the same, but sometimes they are different. For example, if the primary grouping interval is 3, and the secondary is 2, then this corresponds to the pattern "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a pattern contains multiple grouping separators, the interval between the last one and the end of the integer defines the primary grouping size, and the interval between the last two defines the secondary grouping size. All others are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".

非法的图案,如###或####,###,会造成DecimalFormat的设置一个失败的UError code。

Illegal patterns, such as "#.#.#" or "#.###,###", will cause DecimalFormat to set a failing UErrorCode.

这篇关于如何格式化在谷歌API的折线图号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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