How to: Add a Strip to an Axis
- 2 minutes to read
This example demonstrates how strips can be created and customized at runtime.
Since strips reside in an appropriate axis collection, you should first cast your diagram object to the required diagram’s type. Then, you can access the collection via the Axis2D.Strips property.
// Cast the chart's diagram to the XYDiagram type, to access its axes. XYDiagram diagram = (XYDiagram)chartControl1.Diagram; // Create a strip with its maximum and minimum axis value defined. diagram.AxisY.Strips.Add(new Strip("Strip 1", 5, 15)); // Customize the strip's behavior. diagram.AxisY.Strips.Visible = true; diagram.AxisY.Strips.ShowAxisLabel = true; diagram.AxisY.Strips.AxisLabelText = "My Range"; diagram.AxisY.Strips.ShowInLegend = true; diagram.AxisY.Strips.LegendText = "A Sample Strip"; // Customize the strip's appearance. diagram.AxisY.Strips.Color = Color.CornflowerBlue; diagram.AxisY.Strips.FillStyle.FillMode = FillMode.Empty;
The result is shown in the following image.
A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e1369/how-to-add-strips-to-an-axis.