2017-08-11 98 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