This topic is locked

Currency formatting in charts

5/24/2022 4:06:28 PM
PHPRunner Tips and Tricks
admin

If you need to have more control over numbers and currency formatting in charts, this article is for you. All the code here is Javascript, applies without changes to all PHPRunner, ASPRunner.NET and ASPRunerPro. This code is supposed to go to ChartModify event.

For isntance, you need to format your data as German (Euro) currency value, with two digits after comma.

chart.getSeriesAt(0).labels().format (function(){
var num = Number( this.value );
var formatter = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' });
return(formatter.format(num));
});

And here is how it is going to look:

img alt

Another example, value in Euro with no digits after comma:

chart.getSeriesAt(0).labels().format (function(){
var num = Number( this.value );
var formatter = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', maximumFractionDigits: '0' });
return(formatter.format(num));
});

More info about Intl.NumberFormat object.