How to add striplines to an axis in a WinForms Chart?
In WinForms Chart control, StripLines are visual bands drawn in the background of the chart to highlight specific ranges or thresholds on the X or Y axis. They can be vertical (along the X-axis) or horizontal (along the Y-axis), and are commonly used to mark target zones, maintenance windows, danger thresholds, or weekend ranges.
StripLines are stored in the Axis.StripLines collection of a ChartArea and are instances of the StripLine class.
Create and add Stripline to Chart:
A stripline can be added to an axis by using the StripLines.Add() method. The starting position, ending position, and width of the stripline can be configured using the Start, End, and Width properties, respectively. Additionally, the interior style can be applied using the Interior property.
// Creating a Stripline
private ChartStripLine XLine = new ChartStripLine();
XLine.Enabled = true;
XLine.Vertical = true;
// Specifying its position
XLine.Start = 2;
XLine.Width = 0.5;
XLine.End = 3;
XLine.Text = "XLine";
XLine.TextColor = Color.Blue;
XLine.TextAlignment = ContentAlignment.MiddleCenter;
XLine.Font = new Font(XLine.Font.FontFamily.Name, 12);
XLine.Interior = new BrushInfo(230, new BrushInfo(GradientStyle.Vertical, Color.LightYellow, Color.Yellow));
// Adding to the Axes
this.chartControl1.PrimaryXAxis.StripLines.Add(XLine);
'Creating Stripline
Dim XLine As ChartStripLine = New ChartStripLine()
XLine.Enabled = True
XLine.Vertical = True
' Specifying its position
XLine.Start = 2
XLine.Width = 0.5
XLine.End = 3
XLine.Text = "XLine"
XLine.TextColor = Color.Blue
XLine.TextAlignment = ContentAlignment.MiddleCenter
XLine.Font = New Font(XLine.Font.FontFamily.Name, 12)
XLine.Interior = New BrushInfo(230, New BrushInfo(GradientStyle.Vertical, Color.LightYellow, Color.Yellow))
' Adding to the Axes
Me.ChartControl1.PrimaryXAxis.StripLines.Add(XLine)Conclusion
I hope you enjoyed learning about how to add striplines to an axis in a WinForms Chart.
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®, try our 30-day free trial to check out our Winforms Chart and other Winforms components.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!