How to customize the axis label in Windows Forms Charts
This article explains how to change the axis labels in WinForms Charts. For below tabulated data, points with column series will be populated in WinForms Chart as shown in the following image.
Data points
X | Y |
15 | 43000 |
21 | 37000 |
33 | 67000 |
34 | 18000 |
56 | 22000 |
86 | 30000 |
76 | 40000 |
Output
If you want to change the axis label with your desired text, it can be achieved by using the ChartFormatAxisLabel event of chart control. Default axis label has been changed by assigning your desired text in Label property from the argument of ChartFormatAxisLabel as shown in the following code example.
[C#]
this.chartControl1.ChartArea.BackInterior = new Syncfusion.Drawing.BrushInfo(System.Drawing.Color.Transparent); this.chartControl1.Skins = Skins.Midnight; // Add the axis to the chart primary x-axis collection. arrLabel = new List<string>(); arrLabel.Add("Sonata"); arrLabel.Add("Titan"); arrLabel.Add("Fastrack"); arrLabel.Add("Rolex"); arrLabel.Add("Omega"); arrLabel.Add("Timex"); arrLabel.Add("Maruti"); this.chartControl1.ChartFormatAxisLabel += ChartControl1_ChartFormatAxisLabel; panel.Controls.Add(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].ToString(); } } e.Handled = true; }
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