Search code examples
vb.netvisual-studio-2010chartsmschart

Empty points not displaying correcty


I am not able to get an empty point to break the line and be skipped in MSchart. I am using a spline chart for the data and when it reaches an empty point I want to line to break. I have tried setting the marker-style and border-width to nothing and 0 and also tried setting them in code but no success.


Solution

  • You need to add a point at the empty point position and set the IsEmpty property to true.

    Here is an example of how to get an empty point with spline.

    chart1.Series.Clear();
    chart1.Series.Add(new Series());
    chart1.Series[0].ChartType = SeriesChartType.Spline;
    
    chart1.Series[0].Points.Add(new DataPoint(0, 1));
    chart1.Series[0].Points.Add(new DataPoint(1, 4));
    chart1.Series[0].Points.Add(new DataPoint(2, 8));
    chart1.Series[0].Points.Add(new DataPoint(3, 8) { IsEmpty = true });
    chart1.Series[0].Points.Add(new DataPoint(4, 4));
    chart1.Series[0].Points.Add(new DataPoint(5, 2));
    chart1.Series[0].Points.Add(new DataPoint(6, 1));
    

    I have also tried the code above without setting the empty point and using a different technique.

    chart1.Series[0].Points.Add(new DataPoint(0, 1));
    chart1.Series[0].Points.Add(new DataPoint(1, 4));
    chart1.Series[0].Points.Add(new DataPoint(2, 8));
    
    chart1.Series[0].Points.Add(new DataPoint(4, 4));
    chart1.Series[0].Points.Add(new DataPoint(5, 2));
    chart1.Series[0].Points.Add(new DataPoint(6, 1));
    
    chart1.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, chart1.Series[0]);
    

    I just set the IntervalType to days and it worked with the code above. If you are getting strange curves in your line at the borders of the empty point, let me know.

    I believe for the last example above to work using DataManipulator you need to know what interval to expect points.

    Let me know if this does not work for you and how. (Uploaded screenshots of the misbehavior are awesome!)