2017-08-11 80 views
0

我開發了一個帶有MS Chart(.net framework 2.0,visual studio 2010)的網頁。 像這樣的圖片,我必須把百分比標籤放在甜甜圈裏面。在甜甜圈圖表中心放置標籤

enter image description here

我能做些什麼?請幫幫我。提前致謝。

+0

嗨,請張貼你已經嘗試過的代碼.. –

+0

添加'TextAnnotation'到您的圖表。 – jsanalytics

+0

我剛剛使用內置的屬性......只有3個屬性,「內部」,「外部」,「禁用」。 – LSH

回答

1

使用PrePaint事件的TextAnnotation添加到您的圖表:

enter image description here

protected void Chart1_PrePaint(object sender, ChartPaintEventArgs e) 
{ 
    if (e.ChartElement is ChartArea) 
    { 
     var ta = new TextAnnotation(); 
     ta.Text = "81%"; 
     ta.Width = e.Position.Width; 
     ta.Height = e.Position.Height; 
     ta.X = e.Position.X; 
     ta.Y = e.Position.Y; 
     ta.Font = new Font("Ms Sans Serif", 16, FontStyle.Bold); 

     Chart1.Annotations.Add(ta); 
    } 
} 
+0

謝謝! :) :) – LSH

+0

@jsanalytics如何在圖表中繪製一個圓圈而不是文本? – abhishek

+0

@abhishek使用'e.ChartGraphics.Graphics.DrawEllipse()'。 – jsanalytics