【问题标题】:Place label at center of doughnut chart将标签放在圆环图的中心
【发布时间】:2017-08-11 03:42:46
【问题描述】:

我使用 MS Chart(.net framework 2.0,visual studio 2010)开发了一个网页。 像这张图,我得把百分比标签放在甜甜圈里面。

我能做什么?请帮我。提前致谢。

【问题讨论】:

  • 您好,请发布您尝试过的代码..
  • 在您的图表中添加TextAnnotation
  • 我只是使用了内置属性...只有 3 个属性,“inside”、“outside”、“disabled”.. >> Chart.Series["Series"]["PieLabelStyle" ] = "里面";

标签: c# asp.net .net charts mschart


【解决方案1】:

使用PrePaint 事件将TextAnnotation 添加到您的图表中:

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

【讨论】:

  • @jsanalytics 如何在图表内画一个圆圈而不是文字?
  • @abhishek 使用 e.ChartGraphics.Graphics.DrawEllipse().
  • @jsanalytics 要传递什么坐标?
  • @abhishek ,任何适合您的坐标。作为一个建议,您可能想从WidthHeight 计算它,如我上面的答案所示。
猜你喜欢
  • 2014-01-21
  • 1970-01-01
  • 2018-12-05
  • 2021-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多