<ig:XamDataChart.Axes>
<ig:CategoryXAxis FormatLabel="OnCategoryAxisFormatLabel" />
<ig:NumericYAxis FormatLabel="OnPricesAxisFormatLabel" />
<ig:NumericYAxis FormatLabel="OnVolumeAxisFormatLabel" />
</ig:XamDataChart.Axes>
In the XamDataChart™ control, axis labels always display simple text without any formatting applied to them. However, you can change the format of axis labels by setting a formatting string on the Label property of the AxisFormatLabelEventArgs in a handler for the Axis.FormatLabel event.
For example, if you are plotting monetary data along y-axis, the default labels will simply display a decimal representation of your monetary values. If you want to display these values with currency symbols, you need to use C format specifier, followed by a number, specifying decimal precision. For detailed information on .NET Framework composite format strings please refer to the following online resources:
The following code example shows how to format labels on CategoryXAxis
and NumericYAxis
using date formatting and currency formatting:
In XAML:
<ig:XamDataChart.Axes>
<ig:CategoryXAxis FormatLabel="OnCategoryAxisFormatLabel" />
<ig:NumericYAxis FormatLabel="OnPricesAxisFormatLabel" />
<ig:NumericYAxis FormatLabel="OnVolumeAxisFormatLabel" />
</ig:XamDataChart.Axes>
This subscribes the FormatLabel
event to event handlers for each axis. These event handlers are then written in the code behind in the same way as they are in the code snippet below.
In C#:
var commonAxis = new CategoryXAxis();
commonAxis.FormatLabel += OnCategoryAxisFormatLabel;
var pricesAxis = new NumericYAxis();
pricesAxis.FormatLabel += OnPricesAxisFormatLabel;
var volumeAxis = new NumericYAxis();
volumeAxis.FormatLabel += OnVolumeAxisFormatLabel;
...
private void OnVolumeAxisFormatLabel(object sender, AxisFormatLabelEventArgs e)
{
e.Label = string.Format("{0:#,0} K", (double)e.Item);
}
private void OnPricesAxisFormatLabel(object sender, AxisFormatLabelEventArgs e)
{
e.Label = string.Format("{0:C1}", (double)e.Item);
}
private void OnCategoryAxisFormatLabel(object sender, AxisFormatLabelEventArgs e)
{
var dataItem = (Sale)e.Item;
e.Label = string.Format("{0:MMM dd}", dataItem.Date);
}
The following image shows how the XamDataChart control might look with formatted date on CategoryXAxis and formatted currency on NumericYAxis.