MSchart图表中标签位于图表区域内

3

enter image description here

有人能告诉我如何在MSChart上显示总收集量吗?


我在电子邮件中收到了答案,但它是不完整的,为什么我在这里看不到它?请帮忙。 - codery2k
你收到的邮件是关于一个被所有者删除的答案(我能看到它,因为我有超过10K的积分)。 - digEmAll
2个回答

4
您可以使用 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);

我得到了以下的结果:

在此输入图片描述

注意:
有很多的注释类型(如CalloutAnnotationEllipseAnnotation...),它们都有很多属性可以改变样式和行为。您甚至可以设置一个属性来允许注释移动(即AllowMoving=true)。
通过智能感知或MSDN查看注释属性。

@codery2k:你是否将注释添加到了图表的Annotations集合中?(我的更新代码现在展示了如何操作...)此外,你确定已经选择了有效的AnchorX和AnchorY值吗?(它们必须在可见范围内) - digEmAll
是的,我也这样做了,并且我选择了有效的X和Y轴,但仍然没有结果。 :( - codery2k

1
你可以将属性IsDockedInsideChartArea设置为true。你还需要指定图表区域停靠的图例,并将位置属性设置为Auto
legend.IsDockedInsideChartArea = true;
legend.DockedToChartArea = "ChartArea1";

关于此属性以及其他图例属性的更多信息在这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接