Freigeben über


Using Empty Data Points in Chart Controls

Empty data points are points that do not have Y values. These data points are useful for controlling the appearance and structure of your chart's data, as well as handling points whose data is a null value.

Use empty points for:

  • Representing points with NULL values.

  • Changing the appearance of missing data points in the plot area.

  • Aligning two or more series. For information on aligning data, see Aligning Data.

Adding Empty Points

Add an empty point to a data series in one of the following ways:

  • Set the Empty property of a data point to True.

  • Data-bind a data point to values of type DBNull.

  • Use the InsertEmptyPoints method of the DataManipulator class to insert an empty point manually.

The InsertEmptyPoints method uses intervals along the x-axis to check if a data point exists for each of the intervals. If no point exists, the method inserts an empty point. For the empty points to appear properly, specify an interval that corresponds to the Interval, IntervalOffset, IntervalType, and IntervalOffsetType properties in your chart area's primary or secondary axis (ChartArea.AxisX or ChartArea.AxisX2 object).

You can also define a range of X values to check for missing data points.

Note

You can use the InsertEmptyPoints method on multiple series by specifying the names of the series names in a comma separated list for the input parameter.

The following code demonstrates how to insert empty points into two series. The first method call uses one day as the interval to verify Series1 and saves the result in the same series. The second method call uses every Monday as the interval by using an offset, and then stores the resulting data in a new series called ResultSeries.

Imports Dundas.Charting.WebControl
  ...
  
With Chart1.DataManipulator
' Insert empty point for each day if there is no data point present.
.InsertEmptyPoints(1, IntervalType.Days, "Series1")

' Insert empty point for each Monday, but if there is no data point present, then
' Monday is offset by 1 day from the beginning of the week (Sunday).
.InsertEmptyPoints(1, IntervalType.Weeks, 1, IntervalType.Days, "Series2", "ResultSeries")
End With
// Insert empty point for each day if there is no data point present.
Chart1.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "Series1");

// Insert empty point for each Monday, but if there is no data point present, then
// Monday is offset by 1 day from the beginning of the week (Sunday).
Chart1.DataManipulator.InsertEmptyPoints(1, IntervalType.Weeks, 1, IntervalType.Days, "Series2", "ResultSeries");

Changing Empty Point Appearance

Change the visual representation of plotted empty points in applicable chart types using the Series.EmptyPointStyle property. The EmptyPointValue custom property can be used to treat empty points as zeros, or as an average of the points to the left and right of them. For more information on custom properties, see Custom Properties.

The following code demonstrates how to use the Series.EmptyPointStyle property.

' Show marker (red cross) instead of a line for first series.
Chart1.Series("Series1").EmptyPointStyle.BorderWidth = 1
Chart1.Series("Series1").EmptyPointStyle.BorderColor = Color.Black
Chart1.Series("Series1").EmptyPointStyle.MarkerColor = Color.Red
Chart1.Series("Series1").EmptyPointStyle.MarkerSize = 15
Chart1.Series("Series1").EmptyPointStyle.MarkerStyle = MarkerStyle.Cross
 
' Show empty point of second series as thin dotted line (treated as an average).
Chart1.Series("Series2").EmptyPointStyle.BorderStyle = ChartDashStyle.DashDotDot
Chart1.Series("Series2").EmptyPointStyle.MarkerColor = Color.FromArgb(64, 64, 64)
 
' Treat empty point of third series as a zero using the EmptyPointValue custom property.
Chart1.Series("Series3").EmptyPointStyle.BorderWidth = 1
Chart1.Series("Series3").EmptyPointStyle.MarkerColor = Color.FromArgb(0, 192, 0)
Chart1.Series("Series3").EmptyPointStyle.CustomProperties = "EmptyPointValue = Zero"
// Show marker (red cross) instead of a line for first series.
Chart1.Series["Series1"].EmptyPointStyle.BorderWidth = 1;
Chart1.Series["Series1"].EmptyPointStyle.BorderColor = Color.Black;
Chart1.Series["Series1"].EmptyPointStyle.MarkerColor = Color.Red;
Chart1.Series["Series1"].EmptyPointStyle.MarkerSize = 15;
Chart1.Series["Series1"].EmptyPointStyle.MarkerStyle = MarkerStyle.Cross;

// Show empty point of second series as thin dotted line (treated as an average).
Chart1.Series["Series2"].EmptyPointStyle.BorderStyle = ChartDashStyle.DashDotDot;
Chart1.Series["Series2"].EmptyPointStyle.MarkerColor = Color.FromArgb(64, 64, 64);

// Treat empty point of third series as a zero using the EmptyPointValue custom property.
Chart1.Series["Series3"].EmptyPointStyle.BorderWidth = 1;
Chart1.Series["Series3"].EmptyPointStyle.MarkerColor = Color.FromArgb(0, 192, 0);
Chart1.Series["Series3"].EmptyPointStyle.CustomProperties = "EmptyPointValue = Zero";

See Also

Reference

System.Windows.Forms.DataVisualization.Charting

System.Web.UI.DataVisualization.Charting

Concepts

Sorting Data

Aligning Data

Filtering Data

Other Resources

Data Binding and Manipulation