附註 (Chart 控制項)
Chart.Annotations 集合屬性包含 Chart 控制項中的所有附註 (Annotation 物件)。您可以將不同類型的附註加入集合中。它們是做為圖表圖片中詳細說明資料點的註解。您也可以使用它們繪製自訂圖案 (PolylineAnnotation、PolygonAnntation 或 AnnotationGroup)。
注意
在 3D 圖表區域內部使用附註時有限制。如需詳細資訊,請參閱 3D 圖表。
附註有不同的類型:
僅限圖案 (例如 LineAnnotation)
僅限文字 (例如 TextAnnotation)
文字和圖案 (例如 EllipseAnnotation)
群組 (例如 AnnotationGroup)
在執行階段加入附註
若要在執行階段將附註加入 Chart 控制項中,請使用 Chart.Annotations 物件中的 Add 方法。下列程式碼示範如何將 LineAnnotation 加入 Chart 控制項中。
Imports System.Web.UI.DataVisualization.Charting
...
Dim myLine as LineAnnotation = New LineAnnotation()
myLine.Name = "myLine"
myLine.X = 3
myLine.Y = 3
Chart1.Annotations.Add(myLine)
using System.Web.UI.DataVisualization.Charting;
...
LineAnnotation myLine = new LineAnnotation();
myLine.Name = "myLine";
myLine.X = 3;
myLine.Y = 3;
Chart1.Annotations.Add(myLine);
定位附註
透過下列方法定位附註:
使用 Annotation.X 和 Annotation.Y 屬性,在圖表圖片中的任何位置定位附註。
使用 Annotation.AnchorX 和 Annotation.AnchorY 屬性,將附註錨定至圖表圖片中的位置,然後使用智慧標籤在其他標籤周圍予以定位。如需詳細資訊,請參閱標籤。
將其 X 和 Y 座標錨定至繪圖區中的 X 和 Y 軸。若要這麼做,請將 Annotation.AxisX 和 Annotation.AxisY 屬性設為您要使用的軸,然後指定 Annotation.AnchorX 和 Annotation.AnchorY 屬性。
下列程式碼使用 X 和 Y 主軸,在繪圖區中的軸座標 (1,20) 定位附註。
Chart1.Annotations(0).AxisX = Chart1.ChartAreas(0).AxisX; Chart1.Annotations(0).AxisY = Chart1.ChartAreas(0).AxisY; Chart1.Annotations(0).AnchorX = 1; Chart1.Annotations(0).AnchorY = 20;
Chart1.Annotations[0].AxisX = Chart1.ChartAreas[0].AxisX; Chart1.Annotations[0].AxisY = Chart1.ChartAreas[0].AxisY; Chart1.Annotations[0].AnchorX = 1; Chart1.Annotations[0].AnchorY = 20;
使用 Annotation.AnchorDataPoint 屬性將附註錨定至資料點。
下列程式碼會將附註錨定至第一個數列的第二個資料點。
Chart1.Annotations(0).AnchorDataPoint = Chart1.Series(0).Points(1)
Chart1.Annotations[0].AnchorDataPoint = Chart1.Series[0].Points[1];
注意
如果您將附註錨定至資料點,則可以在附註的 Text、Tooltip、Url 和 MapAreaAttributes 屬性中使用資料點的關鍵字。如需詳細資訊,請參閱關鍵字。
調整附註大小
透過下列方法調整附註大小:
在設計階段使用 Annotation.Width 和 Annotation.Height。
在執行階段使用 Annotation.Right 和 Annotation.Bottom。
請參閱
參考
System.Windows.Forms.DataVisualization.Charting
System.Web.UI.DataVisualization.Charting