Search code examples
c#mschart

Broken line chart in Microsoft Chart Control


Is it possible to create a broken line chart with the Microsoft chart control?

Similar to this:

Broken Line Chart

Preferably using the same series.


Solution

  • Yes, it's possible. You can use the DataPoint.IsEmpty property to indicate blank points.
    Sample code:

    Series series = new Series("sample") { ChartType = SeriesChartType.Line, BorderWidth = 2, MarkerSize = 5, MarkerStyle = MarkerStyle.Square };
    series.Points.Add(new DataPoint(0, 1));
    series.Points.Add(new DataPoint(1, 1));
    series.Points.Add(new DataPoint(1.5, double.NaN) { IsEmpty = true });
    series.Points.Add(new DataPoint(2, 1));
    series.Points.Add(new DataPoint(3, 2));
    chart.Series.Add(series);