UPDATE: Starting with version 18.2, we introduced the capability to format any Numeric or Date-Time Value. So, you can set formats demonstrated in this example via the Dashboard Designer's UI using the following settings without writing additional code:
Numeric Format X-Axis Settings
Numeric Format Y-Axis Settings
However, you can still use approaches demonstrated in this example if you wish to implement your custom formatting not supported by the control.
Although our Dashboards do not provide a way to use custom formats and specify formats for axis labels in certain case, there is a way to format axis labels manually. This example illustrates how to format axis labels in a custom manner. For this access the underlying Chart Control in the DashboardItemControlCreated event handler and handle the CustomDrawAxisLabel event to modify the axis labels' content directly.
Note that printed or exported documents containing a dashboard/dashboard item do not reflect appearance settings applied using the events for accessing of underlying controls.
- Form1.cs (VB: Form1.vb)
- Program.cs (VB: Program.vb)
The following three most frequently asked scenarios are represented in this example:
1. Add the currency sign.
private void dashboardDesigner1_DashboardItemControlCreated(object sender, DevExpress.DashboardWin.DashboardItemControlEventArgs e) {
...
e.ChartControl.CustomDrawAxisLabel += ChartControl_CustomDrawAxisLabel1;
...
}
private void ChartControl_CustomDrawAxisLabel1(object sender, DevExpress.XtraCharts.CustomDrawAxisLabelEventArgs e) {
if (e.Item.Axis is SecondaryAxisY)
e.Item.Text = "$" + e.Item.Text;
}
2. Use the ones unit format
private void dashboardDesigner1_DashboardItemControlCreated(object sender, DevExpress.DashboardWin.DashboardItemControlEventArgs e) {
...
e.ChartControl.CustomDrawAxisLabel += ChartControl_CustomDrawAxisLabel2;
...
}
private void ChartControl_CustomDrawAxisLabel2(object sender, DevExpress.XtraCharts.CustomDrawAxisLabelEventArgs e) {
if (e.Item.Axis is SecondaryAxisY)
e.Item.Text = ((double)e.Item.AxisValue).ToString("n0");
}
3. Remove the decimal part of numbers.
private void dashboardDesigner1_DashboardItemControlCreated(object sender, DevExpress.DashboardWin.DashboardItemControlEventArgs e) {
...
e.ChartControl.CustomDrawAxisLabel += ChartControl_CustomDrawAxisLabel3;
...
}
private void ChartControl_CustomDrawAxisLabel3(object sender, DevExpress.XtraCharts.CustomDrawAxisLabelEventArgs e) {
if (e.Item.Axis is AxisX)
e.Item.Text = ((double)e.Item.AxisValue).ToString("n0");
}