Rob*_*ert 5 c# charts annotations line .net-4.5
我确实有一个包含一个系列的工作折线图。现在我想在上面画一条自定义线。我想在图表坐标(如系列中的数据点)而不是像素中设置这条线的起点和终点。据我目前所知,LineAnnotation 可能可以完成这项工作,但我不知道如何做到这一点,到目前为止它根本没有显示任何内容。
我还尝试了 HorizontalLineAnnotation,这个效果很好并显示水平线,但这不是我需要的:
double lineHeight = -35;
HorizontalLineAnnotation ann = new HorizontalLineAnnotation();
ann.AxisX = tc.ChartAreas[0].AxisX;
ann.AxisY = tc.ChartAreas[0].AxisY;
ann.IsSizeAlwaysRelative = false;
ann.AnchorY = lineHeight;
ann.IsInfinitive = true;
ann.ClipToChartArea = tc.ChartAreas[0].Name;
ann.LineColor = Color.Red; ann.LineWidth = 3;
tc.Annotations.Add(ann);
Run Code Online (Sandbox Code Playgroud)
这段代码给了我这个结果:

我想要实现的目标如下(只是一个例子):

我尝试了这段代码,但我不知道如何正确设置坐标:
double lineHeight = -30;
LineAnnotation ann = new LineAnnotation();
ann.AxisX = tc.ChartAreas[0].AxisX;
ann.AxisY = tc.ChartAreas[0].AxisY;
ann.IsSizeAlwaysRelative = true;
ann.AnchorY = lineHeight;
ann.ClipToChartArea = tc.ChartAreas[0].Name;
ann.LineColor = Color.Red; ann.LineWidth = 3;
ann.Width = 200;
ann.X = 2;
ann.Y = -40;
tc.Annotations.Add(ann);
Run Code Online (Sandbox Code Playgroud)
这段代码没有显示任何东西。假设我想从(数据)坐标 (2,-40) 到 (2.8,-32) 绘制一条红线,如上所示 - 我怎样才能实现这一点?
提前致谢!
小智 2
我相信上面的代码只需要分配给 AnchorX 的值。以下对我有用:
LineAnnotation annotation = new LineAnnotation();
annotation.IsSizeAlwaysRelative = false;
annotation.AxisX = chart1.ChartAreas[0].AxisX;
annotation.AxisY = chart1.ChartAreas[0].AxisY;
annotation.AnchorX = 5;
annotation.AnchorY = 100;
annotation.Height = 2.5;
annotation.Width = 3;
annotation.LineWidth = 2;
annotation.StartCap = LineAnchorCapStyle.None;
annotation.EndCap = LineAnchorCapStyle.None;
chart1.Annotations.Add(annotation);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12380 次 |
| 最近记录: |