共用方式為


使用空資料點 (Chart 控制項)

空資料點是沒有 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

其他資源

資料繫結和操作

排序資料

對齊資料

篩選資料