.NET Chart Control: how to use LineAnnotation?

I have a work line diagram with one series. Now I want to draw a custom string on it. I want to set the start and end point of this line in the coordinates of the chart (for example, in the data sets in the series), and not in pixels. As far as I can tell from what I have learned so far, LineAnnotation will probably do the job, but I couldn’t figure out how to do it, so far it has never shown anything.

I also tried HorizontalLineAnnotation, this one works well and shows a horizontal line, but this is not what I need:

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

This code gives me this result: enter image description here

What I want to achieve looks like this (just an example): enter image description here

I tried this code, but I do not see how to set the coordinates correctly:

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

. , () (2, -40) (2.8, -32), - ?

!

+4
3

, , 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);
+2

AnchorDataPoint. :

ann.AnchorDataPoint = tc.Series[0].Points[0];

, AnchorX AnchorY NaN.

+1

. , , , Series . :

private void Line(Point start, Point end)
{
    chart1.Series.Add("line");
    chart1.Series["line"].ChartType = SeriesChartType.Line;
    chart1.Series["line"].Color = System.Drawing.Color.Red;
    chart1.Series["line"].Points.AddXY(start.X, start.Y);
    chart1.Series["line"].Points.AddXY(end.X, end.Y);
}

.

+1

All Articles