Back to Devexpress

CustomDrawAxisLabelEventArgs Class

corelibraries-devexpress-dot-xtracharts-5e5d1e38.md

latest4.7 KB
Original Source

CustomDrawAxisLabelEventArgs Class

Provides data for the ChartControl.CustomDrawAxisLabel (WebChartControl.CustomDrawAxisLabel) event.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public class CustomDrawAxisLabelEventArgs :
    EventArgs
vb
Public Class CustomDrawAxisLabelEventArgs
    Inherits EventArgs

CustomDrawAxisLabelEventArgs is the data class for the following events:

LibraryRelated API Members
WinForms ControlsChartControl.CustomDrawAxisLabel
ASP.NET Web Forms ControlsWebChartControl.CustomDrawAxisLabel
.NET Reporting ToolsXRChart.CustomDrawAxisLabel

Remarks

The ChartControl.CustomDrawAxisLabel event occurs before axis label items are drawn, when the chart’s contents are being drawn.

The CustomDrawAxisLabelEventArgs class introduces the CustomDrawAxisLabelEventArgs.Item property which provides access to individual AxisLabelItem objects.

Note, that CustomDrawAxisLabelEventArgs objects are automatically created, initialized and passed to ChartControl.CustomDrawAxisLabel event handlers.

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. For example, based on some criteria (e.g. an axis value threshold), you can apply different formatting to axis labels.

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

Note

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

The following code demonstrates one possible implementation of this capability.

csharp
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) {
            e.Item.TextColor = Color.Red;
        }
        else if (axisValue > 0) {
            e.Item.Text = "+" + e.Item.Text;
            e.Item.TextColor = Color.Green;
        }
        else if (axisValue == 0) {
            e.Item.Text = "Zero";
        }
    }
}
vb
Private Sub chartControl1_CustomDrawAxisLabel(sender As Object, e As CustomDrawAxisLabelEventArgs)
   Dim axis As AxisBase = e.Item.Axis
   If TypeOf axis Is AxisY Or TypeOf axis Is AxisY3D Or TypeOf axis Is RadarAxisY Then
      Dim axisValue As Double = CDbl(e.Item.AxisValue)
      If axisValue < 0 Then
         e.Item.TextColor = Color.Red
      Else
         If axisValue > 0 Then
            e.Item.Text = "+" + e.Item.Text
            e.Item.TextColor = Color.Green
         Else
            If axisValue = 0 Then
               e.Item.Text = "Zero"
            End If
         End If
      End If
   End If
End Sub

Inheritance

Object EventArgs CustomDrawAxisLabelEventArgs

See Also

CustomDrawAxisLabelEventArgs Members

DevExpress.XtraCharts Namespace