Devexpress MVC Chart Axis label to format number by M (million) or K (thousand)

By | 5. May 2017

Often it is enough to show on chart axis label general indicative number instead of full precision figure. Also long figures take a lot of precious space.

So instead 890 152 000 the  890M would do fine. So how to do it in case of DevExpress Chart control MVC extension. Unlike in case of Windows Desktop or WinForms control it is a bit harded to figure out as the handy properties editor is not available.

But actually the solution is quite simple. Key is to implement CustomDrawAxisLabel event.

Inside event use Custom Numeric Format Strings functionality. Particularly the “,” custom specifier is key ( The “,” Custom Specifier ).

For k use “{0:#,k}” and for M use “{0:#,,M}” format

 

This code also shows how to set axis measure unit and grid alignment.

graph

 

Leave a Reply