2012-07-30 91 views
2

enter image description here圖表區域內的MSChart標籤

有人可以告訴我怎樣才能顯示在MSChart的

+0

我在電子郵件中收到了不完整的答案,但是我在這裏看不到它,爲什麼?請幫助。 – codery2k 2012-07-31 03:33:22

+0

你收到的郵件是關於一個已被業主刪除的答案(我可以看到它,因爲我有超過10K點)。 – digEmAll 2012-08-05 08:17:23

回答

3

的總集,您可以使用chart.Annotations屬性來獲得類似的結果。

例如用下面的代碼(位於填充圖表後):

var ann = new RectangleAnnotation(); 
ann.Text = "Total Collection" + Environment.NewLine + "250 Billion"; 
ann.IsMultiline = true; 
ann.AxisX = this.chart1.ChartAreas[0].AxisX; 
ann.AxisY = this.chart1.ChartAreas[0].AxisY; 
ann.AnchorX = 9; // as you can see from the image below, 
ann.AnchorY = 41; // these values are inside the range 

// add the annotation to the chart annotations list 
this.chart1.Annotations.Add(ann); 

我得到了以下結果:

enter image description here

NB:
有很多註解類型(CalloutAnnotation,EllipseAnnotation ...),它們有很多屬性可以改變樣式和行爲。您甚至可以設置一個屬性以允許註釋移動(即AllowMoving=true)。

通過intellisense或MSDN查看註釋屬性。

+0

@ codery2k:您是否將註釋添加到圖表中。註釋集合? (我現在更新的代碼顯示了......)另外,你確定你已經選擇了有效的AnchorX和AnchorY值嗎? (它們必須在可見範圍內) – digEmAll 2012-09-03 13:46:38

+0

是的,我也是這樣做的,我選擇了有效的X軸和Y軸,但仍然沒有結果。 :( – codery2k 2012-09-04 05:12:19

+0

@ codery2k:這真的很奇怪...... – digEmAll 2012-09-04 08:35:57

1

您可以將屬性IsDockedInsideChartArea設置爲true。您還需要指定圖例所對應的ChartArea,並將位置屬性設置爲Auto

legend.IsDockedInsideChartArea = true; 
legend.DockedToChartArea = "ChartArea1"; 

有關於此和其他圖例屬性here的更多信息。