Number Formatting in FusionCharts
FusionCharts offers you a lot of options to format your numbers on the chart. From number prefixes and suffixes to controlling the decimal places, FusionCharts lets you do it all. In this section, we'll see the number formatting properties supported by FusionCharts. We'll start with setting decimal precisions for the numbers on chart.
Controlling decimal precision
All the charts in FusionCharts support the attribute decimalPrecision. If not specified a chart automatically shows number up to 2 decimal places. This single attribute lets you control the decimal precision of all the numbers on the chart. Using this attribute, you can globally set the number of decimal places of ALL numbers of the chart. For e.g., if you have numbers on your chart as 12.432,13.4 and 13 and you set <chart ... decimalPrecision='0' >, the numbers would be converted to 12, 13 and 13 respectively.
Chart without any decimal formatting applied | With decimals set to 0
Similarly, if you had data as 0.12342, 0.134 and 0.13, with decimalPresion not specified, FusionCharts would output 0.12, 0.13 and 0.13 respectively. Now you set decimalPrecision to 4 and will get 0.1243 ,0.1340 and 0..1300 respectively.
Chart without any decimal formatting applied | Forcing trailing zeroes by setting decimalPrecision='4'
Automatic number formatting
FusionCharts automatically formats your numbers by adding K,M (Kilo, Million) and proper commas to the numbers. Shown below is an example:
In the above image, the data for chart is 12500, 13400 and 13300. FusionCharts automatically formats the number scaling to convert to K (Thousands) & M (Millions). If you do not wish to truncate numbers in this manner, just use: <chart formatNumberScale='0'..decimalPrecision='0'...> When you now view the chart, you'll get the following output:
You can see above that FusionCharts is now showing full numbers on the chart. It has also added commas to the numbers at the required places. If you do not need the commas too, set formatNumber=0. But, setting formatNumber=0 wouldn't format any decimal places too (even if explicitly specified in XML). Shown below is an example with <chart ... formatNumber='0' formatNumberScale='0' ..decimalPrecision='0'...> :
You can see that the commas have been removed from numbers.
Setting custom thousand and decimal separator character
By default, FusionCharts uses . (dot) as decimal separator and , (comma) as thousand separator character. However, you can customize this character depending on your requirements. To do so, use the decimalSeparator and thousandSeparator attribute. For example, let's set our thousands separator as dot and decimal separator as comma. To do so, you'll have to use the following xml: <chart ... decimalSeparator=',' thousandSeparator='.' > Shown below is the output.
Chart with default decimal and thousand separator. FusionCharts by default separates thousands using commas and decimals using dots. | Chart with swapped decimal and thousands separator character.
Adding number prefix and suffix
FusionCharts allows you to add a prefix or suffix to all numbers on the chart. You can use the following attributes of <chart> element to attain the same: numberPrefix="$" : Using this attribute, you could add prefix to all the numbers visible on the graph. For example, to represent all dollars figure on the chart, you could specify this attribute to ' $' to show like $40000, $50000. numberSuffix="p.a" : Using this attribute, you could add suffix to all the numbers visible on the graph. For example, to represent all figure quantified as per annum on the chart, you could specify this attribute to ' /a' to show like 40000/a, 50000/a. If you intend to use special characters for numberPrefix or numberSuffix, you'll need to URL Encode them when using dataXML method. For example, if you wish to have numberSuffix as % (like 30%), you'll need to specify it as under: numberSuffix='%25' In dataURL method, you can directly specify the character. Examples:
Number Prefix set as $ for the chart | Number Suffix Set as %