将图表点标签移动到另一个位置,并用箭头将其连接 [英] Move chart point label to another position and connect them with an arrow

查看:102
本文介绍了将图表点标签移动到另一个位置,并用箭头将其连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图表中添加26个点,并将它们从a标记为z.

I want to add 26 points into chart and label them from a to z.

如何将标签从其原始位置移动到附近位置,以及如何使用箭头或其他符号连接标签和对应点?演示图如下​​所示:

How do I move the label to a nearby position from its original position and how to use an arrow or other symbols to connect the label and corresponding point? The demo chart looks like this :

推荐答案

DataPoint Labels被自动自动放置,并且只有很少的选择来影响它们的位置.

The DataPoint Labels are being placed pretty much automatically and you have only very few options to influence their position.

SmartLabels,但是它们只允许您控制避免它们重叠时的行为.

There are SmartLabels but they only allow you to control the behaviour when it comes to avoiding them to overlap.

因此,我认为您必须使用

So I think instead of Labels you will have to resort to Annotations.

实际上要复制图像,您需要一个DataPoint%28v = vs.110%29.aspx"rel =" nofollow noreferrer>文本注释,并固定到该DataPoint ..:

Infact to replicate your image you need one LineAnnotation and one TextAnnotation per DataPoint you want labelled, anchored to that DataPoint..:

让我们假设您正在将DataPoints逐个添加到Series S1:

Lets assume you are adding the DataPoints to your Series S1one by one:

int p = S1.Points.AddXY(yourXValue, yourYValue);
string s = yourLabelText;
DataPoint dp = S1.Points[p];

现在您需要创建一个TextAnnotation,或者精确地说是

Now you need to create one TextAnnotation, or to be precise a RectangleAnnotation, which is a subclass of TextAnnotation allowing for background and creating a border:

RectangleAnnotation ta = new RectangleAnnotation();
ta.AnchorDataPoint = dp;
ta.AnchorOffsetX = 5;     // *
ta.AnchorOffsetY = 3;     // *
ta.AnchorAlignment = ContentAlignment.BottomLeft;
ta.Text = s;
chart1.Annotations.Add(ta);

请注意我如何在此处设置位置(*),以使注释稍微向上和向右移动.这些数字是不是像素,而是图表大小的百分比.您需要做一些尝试才能找到自己喜欢的值.优点是,当您调整图表大小或缩放时,距离会缩放.

Note how I set the positioning here (*) to move the annotation a little up and right. The numbers are not pixels but percentages of the chart size. You need to experiment a little to find values you like. The Advantage is that the distance will scale when you resize or zoom the chart.

现在,我们添加箭头:

LineAnnotation la = new LineAnnotation();
la.SetAnchor(dp);
la.AnchorOffsetX = 0.5;   // (**)
la.AnchorOffsetY = -0.5;  // (**)
la.StartCap = LineAnchorCapStyle.Arrow;
la.Width =    ta.AnchorOffsetX - la.AnchorOffsetX;
la.Height = - ta.AnchorOffsetY + la.AnchorOffsetY;  // (***)           
chart1.Annotations.Add(la);

(**)我将起点从DataPoint移了一点,所以箭头不会与该点的圆重叠.

(**) I move the starting point a little off the DataPoint so the arrow won't overlap the circle of the point.

(***)注意,高度需要从该点向上指向,因此它为负!

(***) Note that the height needs to point upward from the point, so it is negative!

您将需要微调一些数字.

You will want to fine-tune some of the numbers..

这篇关于将图表点标签移动到另一个位置,并用箭头将其连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆