Articles in this section

How to customize the axis label in Windows Forms Charts?

This article explains how to change the axis labels in WinForms Charts. For the tabulated data below, points with column series will be populated in the WinForms Chart, as illustrated in the following image.

Data Points

 

X

Y

15

43000

21

37000

33

67000

34

18000

56

22000

86

30000

76

40000

 

Output

 

WinForms chart default view

 

To change the axis label to your desired text, use the ChartFormatAxisLabel event of the chart control. The default axis label is changed by assigning your desired text to the Label property from the argument of ChartFormatAxisLabel, as shown in the following code example.

For more details on customize the axis label, refer to the WinForms Chart documentation.

// Declare at class level:
private List<string> arrLabel;

private void InitializeChartSetup()
{
    // Prepare labels
    arrLabel = new List<string>
    {
        "Sonata",
        "Titan",
        "Fastrack",
        "Rolex",
        "Omega",
        "Timex",
        "Maruti"
    };
    
    this.chartControl1 = new ChartControl();
    . . .

    // Wire up the axis label formatting event
    this.chartControl1.ChartFormatAxisLabel += ChartControl1_ChartFormatAxisLabel;

    // Add chart to panel
    this.panel.Controls.Add(this.chartControl1);
}

private void ChartControl1_ChartFormatAxisLabel(object sender, ChartFormatAxisLabelEventArgs e)
{
    int index = (int)e.Value;

    if (e.AxisOrientation == ChartOrientation.Horizontal)
    {
        if (index >= 0 && index < arrLabel.Count)
        {
            e.Label = arrLabel[index];
        }
    }

    e.Handled = true; // use custom label
}
' Declare at class level:
Private arrLabel As List(Of String)

Private Sub InitializeChartSetup()
' Prepare labels
arrLabel = New List(Of String)()
arrLabel.Add("Sonata")
arrLabel.Add("Titan")
arrLabel.Add("Fastrack")
arrLabel.Add("Rolex")
arrLabel.Add("Omega")
arrLabel.Add("Timex")
arrLabel.Add("Maruti")

Me.ChartControl1 = New ChartControl()
. . .

' Wire up the axis label formatting event
AddHandler Me.chartControl1.ChartFormatAxisLabel, AddressOf ChartControl1_ChartFormatAxisLabel

' Add chart to panel
Me.panel.Controls.Add(Me.chartControl1)
End Sub

Private Sub ChartControl1_ChartFormatAxisLabel(ByVal sender As Object, ByVal e As ChartFormatAxisLabelEventArgs)
    Dim index As Integer = CInt(e.Value)

    If e.AxisOrientation = ChartOrientation.Horizontal Then
        If index >= 0 AndAlso index < arrLabel.Count Then
            e.Label = arrLabel(index).ToString()
        End If
    End If

' use custom label
    e.Handled = True
End Sub

View the sample in GitHub.

 

Column series with Custom labels in Windows Forms Chart

Conclusion

I hope you enjoyed learning about how to customize the axis label in Windows Forms Charts.

You can refer to our WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Chart examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


See also

How to get event notification when clicking in axis label

How to display the axis edge labels fully

How to implement Multiple Axes in chart

How to set range for log axis

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied