Place label at center of doughnut chart

妖精的绣舞 提交于 2020-05-18 19:50:43

问题


I've developed a web page with MS Chart (.net framework 2.0, visual studio 2010). Like this picture, I have to put the percentage label inside the doughnut.

What can I do? Please help me. Thanks in advance.


回答1:


Use the PrePaint event to add a TextAnnotation to your chart:

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);
    }
}


来源:https://stackoverflow.com/questions/45626619/place-label-at-center-of-doughnut-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!