Version

Configuring Axis Label Format

In the UltraDataChart™ 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 any type of Axis.

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 C#:

var commonAxis = new CategoryXAxis();
var pricesAxis = new NumericYAxis();
var volumeAxis = new NumericYAxis();

commonAxis.Label = "Date:MM/dd";
// or using an event
commonAxis.FormatLabel += OnCategoryAxisFormatLabel;

pricesAxis.Label = "Price:C1";
// or using an event
pricesAxis.FormatLabel += OnPricesAxisFormatLabel;

volumeAxis.Label = "Value:#,0 K";
// or using an event
volumeAxis.FormatLabel += OnVolumeAxisFormatLabel;

// Event handlers
string OnCategoryAxisFormatLabel(AxisLabelInfo info)
{
    return string.Format("{0:MM/dd}", info.DateValue);
}

string OnPricesAxisFormatLabel(AxisLabelInfo info)
{
    return string.Format("{0:C1}", info.Value);
}

string OnVolumeAxisFormatLabel(AxisLabelInfo info)
{
    return string.Format("{0:#,0} K", info.Value);
}

In Visual Basic:

Dim commonAxis As New CategoryXAxis()
Dim pricesAxis As New NumericYAxis()
Dim volumeAxis As New NumericYAxis()

commonAxis.Label = "Date:MM/dd"
' or using an event
AddHandler commonAxis.FormatLabel, AddressOf OnCategoryAxisFormatLabel

pricesAxis.Label = "Price:C1"
' or using an event
AddHandler pricesAxis.FormatLabel, AddressOf OnPricesAxisFormatLabel

volumeAxis.Label = "Value:#,0 K"
' or using an event
AddHandler volumeAxis.FormatLabel, AddressOf OnVolumeAxisFormatLabel

' Event handlers
Function OnCategoryAxisFormatLabel(info As AxisLabelInfo) As String
    Return String.Format("{0:MM/dd}", info.DateValue)
End Function

Function OnPricesAxisFormatLabel(info As AxisLabelInfo) As String
    Dim value = CType(info.Value, Double)
    Return String.Format("{0:C1}", value)
End Function

Function OnVolumeAxisFormatLabel(info As AxisLabelInfo) As String
    Dim value = info.Value
    Return String.Format("{0:#,0} K", value)
End Function

The following image shows how the UltraDataChart control might look with formatted date on CategoryXAxis and formatted currency on NumericYAxis.

DataChart Axes Axis Label Format 01.png