Articles in this section

How to handle empty point gaps in WinForms Chart?

Plotting data in the WinForms Chart automatically ignores empty points and adds empty segments or gaps. This section explains how to avoid creating an empty segment by using built-in APIs.

 

Generated gap for empty data points

For the provided NaN values, gaps will be created. By setting the AllowGapForEmptyPoints property of the Chart control to false, you can prevent the creation of empty segments, and the chart plotting will appear as shown below.

For more details on handling empty points, refer to the WinForms Chart documentation.

Private void InitializeComponent()
{
    // Create and configure chart
    this.chartControl = new ChartControl();
    . . .

    // Treat empty points as continuous (no gap)
    chartControl.AllowGapForEmptyPoints = false;

    // Series with NaN to represent missing points
    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)); // empty
    chartSeries.Points.Add(new ChartPoint(2004, 24));
    chartSeries.Points.Add(new ChartPoint(2005, 40));
    chartSeries.Points.Add(new ChartPoint(2006, double.NaN)); // empty
    chartSeries.Points.Add(new ChartPoint(2007, 20));
    chartSeries.Points.Add(new ChartPoint(2008, 30));
    this.chartControl.Series.Add(chartSeries);

    // Add chart to form
    this.Controls.Add(this.chartControl);
}
Private Sub InitializeComponent()
    ' Create and configure chart
    Me.chartControl = New ChartControl()
    . . .

    ' Hide gap for empty points
    Me.chartControl.AllowGapForEmptyPoints = False

    ' Create line series with some missing points (Double.NaN)
    Me.chartSeries = New ChartSeries()
    Me.chartSeries.Type = ChartSeriesType.Line
    Me.chartSeries.Points.Add(New ChartPoint(2001, 12))
    Me.chartSeries.Points.Add(New ChartPoint(2002, 14))
    Me.chartSeries.Points.Add(New ChartPoint(2003, Double.NaN)) ' empty point
    Me.chartSeries.Points.Add(New ChartPoint(2004, 24))
    Me.chartSeries.Points.Add(New ChartPoint(2005, 40))
    Me.chartSeries.Points.Add(New ChartPoint(2006, Double.NaN)) ' empty point
    Me.chartSeries.Points.Add(New ChartPoint(2007, 20))
    Me.chartSeries.Points.Add(New ChartPoint(2008, 30))

    ' Add series to chart
    Me.chartControl.Series.Add(Me.chartSeries)
    Me.Controls.Add(Me.chartControl)

End Sub

Output

 Ignore Gap for Empty points in WinForms Charts


Conclusion

I hope you enjoyed learning how to handle empty point gaps in WinForms 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 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



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