VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=Formatter Plugin——VisActor/VChart tutorial documents!!!###!!!!!!###!!!description=Starting from `v1.10.0`, VChart supports the formatting extension plugin, providing more capabilities for formatting strings, including:1. Numeric formatting2. Time formatting3. Data variable replacement!!!###!!!
Formatter Plugin
Starting from v1.10.0, VChart supports the formatting extension plugin, providing more capabilities for formatting strings, including:
Numeric formatting
Time formatting
Data variable replacement
How to use the formatting plugin
The formatted string supports replacement with data content, and the variable name needs to be enclosed in single braces {}, for example:
// Data{
year:2016,
population:899447},
formatter: `"The population in {year} year is {population}"`。
Numeric
The numeric formatting adopts a formatting convention similar to d3-formatter. In the formatting expression, it is separated from the variable name by a colon, for example:
Two decimal places: {value:.2f}
Thousands separator, no decimal places:{value:,.0f}
Thousands separator, one decimal place: {value:,.1f}
Common formatting types include:
e: exponent notation.
f: fixed point notation.
g: either decimal or exponent notation, rounded to significant digits.
r: decimal notation, rounded to significant digits.
s: decimal notation with an SI prefix, rounded to significant digits.
%: multiply by 100, and then decimal notation with a percent sign.
p: multiply by 100, round to significant digits, and then decimal notation with a percent sign.
b: binary notation, rounded to integer.
o: octal notation, rounded to integer.
d: decimal notation, rounded to integer.
x: hexadecimal notation, using lower-case letters, rounded to integer.
X: hexadecimal notation, using upper-case letters, rounded to integer.
c: character data, for a string of text.
In addition, the formatting plugin has extended two common numeric formatting logics:
t:keep the specified number of decimal places, without round off.
z:decimal value, rounded to significant digits; integer value, no decimal part.
The ~ option trims insignificant trailing zeros across all format types. This is most commonly used in conjunction with types r, e, s and %. For example: