Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display labels in each point in ZedGraph?

How can I display labels for each point plotted in a ZedGraph chart?

like image 300
eKek0 Avatar asked Jan 24 '23 15:01

eKek0


2 Answers

Since that site is down now, here's a code snippet to give an example of how to do it:

myLine.GetRange(out other, out other, out minY, out maxY, false, false, myPane);
                double Yinterval = Math.Abs(maxY - minY) / 25;
                // Loop to add text labels to the points
                for (int i = 0; i < tempPoints.Count; i++) {
                    // Get the pointpair
                    ZedGraph.PointPair pt = tempPoints[i];
                    // Create a text label from the Y data value
                    ZedGraph.TextObj text = new ZedGraph.TextObj(pt.Y.ToString(), pt.X, pt.Y + Yinterval,
                        ZedGraph.CoordType.AxisXYScale, ZedGraph.AlignH.Left, ZedGraph.AlignV.Center);
                    text.FontSpec.FontColor = tempHolder.Color;
                    text.ZOrder = ZedGraph.ZOrder.A_InFront;
                    // Hide the border and the fill
                    text.FontSpec.Border.IsVisible = false;
                    text.FontSpec.Fill.IsVisible = false;
                    text.FontSpec.Size = 10f;
                    text.FontSpec.Angle = 45;


                    string lblString = "name";

                    Link lblLink = new Link(lblString, "#", "");
                    text.Link = lblLink;

                    myPane.GraphObjList.Add(text);
                }
like image 187
Jared Avatar answered Jan 26 '23 04:01

Jared


For each point, create a text object with your label text, and add it to the graph.

The Point Label Demo demonstrates...

like image 23
Shog9 Avatar answered Jan 26 '23 04:01

Shog9