How to handle the empty points gap in WinForms Chart?
Plotting data in the WinForms Chart will automatically ignore the empty points if anything has and added the empty segment or gap in it. This section explains how to avoid creating an empty segment by using its inbuild APIs.
For the provided NaN values, it will create a gap. By setting ‘false’ to the AllowGapForEmptyPoints property of Chart control, it will avoid the empty segment creation and will provide a chart plotting as shown below.
private void InitializeComponent() { this.SuspendLayout(); this.ClientSize = new System.Drawing.Size(800, 450); this.chartControl = new ChartControl(); this.chartControl.Location = new System.Drawing.Point(143, 55); this.chartControl.Palette = ChartColorPalette.Colorful; this.chartControl.Size = new System.Drawing.Size(452, 331); this.chartControl.TabIndex = 2; this.chartControl.ShowLegend = false; this.chartControl.PrimaryXAxis.DrawMinorGrid = false; this.chartControl.PrimaryXAxis.DrawGrid = false; this.chartControl.PrimaryXAxis.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift; this.chartControl.PrimaryYAxis.DrawMinorGrid = false; this.chartControl.PrimaryYAxis.DrawGrid = false; this.chartControl.PrimaryYAxis.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift; //Hide Gap for empty points. chartControl.AllowGapForEmptyPoints = false; chartSeries = new ChartSeries(); chartSeries.Type = ChartSeriesType.Line; chartSeries.Points.Add(new ChartPoint(2001, 12)); chartSeries.Points.Add(new ChartPoint(2002, 14)); chartSeries.Points.Add(new ChartPoint(2003, double.NaN)); chartSeries.Points.Add(new ChartPoint(2004, 24)); chartSeries.Points.Add(new ChartPoint(2005, 40)); chartSeries.Points.Add(new ChartPoint(2006, double.NaN)); chartSeries.Points.Add(new ChartPoint(2007, 20)); chartSeries.Points.Add(new ChartPoint(2008, 30)); this.chartControl.Series.Add(chartSeries); this.Controls.Add(this.chartControl); this.ResumeLayout(false); this.PerformLayout(); }
Output
See also
How to specify the point as an empty point programmatically
How to create Chart in VB .NET Windows Forms
How to add data to the WinForms Chart
Conclusion
I hope you enjoyed learning how to handle the empty points gap in WinForms Charts.
You can refer to WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Chart example 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!