I need to format the numbers in the axis and the numbers that appear when you hover your mouse over the line chart.
相关问题
- Google places autocomplete suggestion without coun
- Karate API Testing - Access variable value across
- How to verify laravel passport api token in node /
- Converting byte array output into Blob corrupts fi
- How to handle “App is temporarily blocked from log
相关文章
- 我用scrapy写了一个蛮简单的爬虫怎么封装成一个api啊
- 后端给前端的API接口是怎么用代码写的
- Convert C# Object to Json Object
- Android camera2 API get focus distance in AF mode
- Getting all listing images from an Etsy shop
- Is there an API to get statictics on Google Play d
- How to search specific user's tracks by tag wi
- Django REST Framework - OAuth2 Consumer API from e
If you need to simply format all numbers shown in the graph, in the hover and in the axis according to the locale of a country, the simplest in IMHO is to use the country code when loading the library.
E.g.:
That is the way I would format all numbers using space separators for thousands and a comma for the decimal place.
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.
Step 2: Putting the pattern in your code
Here's the code:
vAxis: {title: 'Time', format:'0.0E00'}
formats the labels on the vertical axis.This formats the numbers you see when you hover over points on the line chart:
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).The last two lines of code:
are for you two compare with your own chart. Replace
fchartvar
,dataTable
andfchart
by the names used in your code. If you're using something other than line chart, replaceLineChart
with the chart you're using.An example of
0.0E00
is turning1,234
into1.2E03
.Step 1: Finding the right pattern
Google NumberFormat documentation
NumberFormat supports the following options, passed in to the constructor: (source: Google NumberFormat documentation)
decimalSymbol
fractionDigits
groupingSymbol
negativeColor
negativeParens
pattern
A format string. When provided, all other options are ignored, except negativeColor.
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
suffix
ICU DecimalFormat Reference
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):
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#)".
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.
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 "#,##,###,####" == "###,###,####" == "##,#,###,####".
Illegal patterns, such as "#.#.#" or "#.###,###", will cause DecimalFormat to set a failing UErrorCode.