Search code examples
c#zedgraph

Labelling and circle a specific point in zedgraph


I am currently doing a project in which I've managed to identify the peak I want. However, I wanted to do more like circling the particular point with a label attached to it. Is it possible to do that in Zedgraph?

I've attached a snippet of my code which only include a text label to that point, and I wanted to do more so people will identify the point more easily.

PointPair pt = myCurve.Points[i-1];
const double offset = 0.8;

TextObj text = new TextObj("P", pt.X, pt.Y + offset,
CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
text.ZOrder = ZOrder.A_InFront;
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill.IsVisible = false;
text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );

myPane.GraphObjList.Add(text);

Any help is appreciated! Thanks!


Solution

  • Make a LineItem as follows

    LineItem line = new LineItem("Point", new double[] {pt.x}, new double[] {pt.y}, Color.Black, SymbolType.Circle);
    line.Symbol.Size = 20;
    line.Symbol.Fill = new Fill(Color.Transparent);
    myPane.CurveList.Add(line);
    

    This should create a large empty circle centered around your point. Obviously, you can adjust color and size as you see fit, and the ZOrder if you need to. You might want to adjust your legend so it doesn't include this point. Alternatively, you can name this line with your label and leave it in the legend as a way of tagging it. The only other way for a label is to do what you're doing, as I'm not sure of a way to associate labels directly to a line.