Share via


使用图表控件中的空数据点

空数据点是没有 Y 值的点。在控制图表数据的外观和结构以及处理数据为 Null 值的点时,这些数据点非常有用。

空点可用于:

  • 使用 NULL 值表示点。

  • 更改绘图区中缺失的数据点的外观。

  • 将两个或更多序列对齐。有关对齐数据的信息,请参见对齐数据

添加空点

使用下列方式之一可在数据序列中添加空点:

  • 将数据点的 Empty 属性设置为 True。

  • 将数据点数据绑定到 DBNull 类型的值。

  • 使用 DataManipulator 类的 InsertEmptyPoints 方法手动插入空点。

InsertEmptyPoints 方法沿 X 轴以一定间隔检查每个间隔内是否存在数据点。如果数据点不存在,则该方法插入一个空点。若要正确显示空点,请指定一个间隔,该间隔对应于图表区域主轴或辅助轴(ChartArea.AxisXChartArea.AxisX2 对象)中的 IntervalIntervalOffsetIntervalTypeIntervalOffsetType 属性。

也可以通过定义 X 值的范围检查数据点缺失情况。

备注

通过以逗号分隔列表的形式为相应的输入参数指定多个序列名,可以针对多个序列使用 InsertEmptyPoints 方法。

下面的代码说明如何在两个序列中插入空点。第一个方法调用将一天作为验证 Series1 的间隔,并将结果保存在同一序列中。第二个方法调用通过使用偏移,将每个周一作为间隔,然后将结果数据存储在名为 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");

更改空点外观

使用 Series.EmptyPointStyle 属性可更改适用图表类型中所绘制的空点的直观表示形式。EmptyPointValue 自定义属性可用于将空点视为零,或视为空点左侧和右侧的点的平均值。有关自定义属性的更多信息,请参见自定义属性

下面的代码演示如何使用 Series.EmptyPointStyle 属性。

' 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";

请参见

参考

System.Windows.Forms.DataVisualization.Charting

System.Web.UI.DataVisualization.Charting

概念

对数据进行排序

对齐数据

筛选数据

其他资源

数据绑定和操纵