Skip to main content

ChartControl.CustomDrawAxisLabel Event

Occurs before axis label items are drawn when the chart’s contents are being drawn.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.UI.dll

NuGet Package: DevExpress.Win.Charts

Declaration

public event CustomDrawAxisLabelEventHandler CustomDrawAxisLabel

Event Data

The CustomDrawAxisLabel event's data class is CustomDrawAxisLabelEventArgs. The following properties provide information specific to this event:

Property Description
Item Provides access to individual axis label items.

Remarks

Use the CustomDrawAxisLabel event, to individually adjust the appearance of axis labels, e.g. based on their axis values.

The CustomDrawAxisLabel event is raised before every AxisLabelItem object is painted. The event parameter’s CustomDrawAxisLabelEventArgs.Item property provides an AxisLabelItem object, which represents an individual axis label item. So, for an axis label item obtained in the CustomDrawAxisLabel event, it’s possible to obtain its axis value (or internal value, if it’s needed), its font and appearance settings, and also access the properties of the associated axis itself.

Note that in order to access settings specific for 3D charts axis labels, the return value of the CustomDrawAxisLabelEventArgs.Item property should be typecast to the corresponding type (AxisLabel3DItem). And, for Radar and Polar charts only the X-axis labels are available, and can be obtained and customized in this event.

For more information, refer to Axis Labels.

Example

Apart from the capability to customize the overall appearance of axis labels, you can obtain individual axis labels at runtime. Then, it’s possible to apply all the options available for axis labels to them, individually. You can apply different formatting to axis labels based on some criteria (for example, an axis value threshold).

For this, the special ChartControl.CustomDrawAxisLabel event is introduced. Handle it to obtain axis labels.

Note

For the WebChartControl you should handle its WebChartControl.CustomDrawAxisLabel event to implement this task.

The following code demonstrates one possible implementation of this capability.

View Example

private void chartControl1_CustomDrawAxisLabel(object sender, CustomDrawAxisLabelEventArgs e) {
    AxisBase axis = e.Item.Axis;
    if (axis is AxisY || axis is AxisY3D || axis is RadarAxisY) {
        double axisValue = (double)e.Item.AxisValue;
        if (axisValue < 0)
            // Customize the axis label's color.
            e.Item.TextColor = Color.Red;
        else if (axisValue > 0) {
            // Customize the axis label's text and color.
            e.Item.Text = "+" + e.Item.Text;
            e.Item.TextColor = Color.Green;
        }
        else if (axisValue == 0) {
            // Hide the axis labels.
            e.Item.Text = "";
        }
    }
}        

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawAxisLabel event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also