Click here to Skip to main content
15,884,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i'm trying to use PolygonAnnotation to draw a Polygon within a chart where i have four points that i would like to use as vertex.
These Points are putted at runtime in a Bubble Series
C#
System.Windows.Forms.DataVisualization.Charting.Series serieSA = chartCartesian.Series.FindByName("SeriesSafetyArea");
            
            DataPoint dpA = new DataPoint(radarConfigured.SafetyArea.PointA.X,new Double[]{radarConfigured.SafetyArea.PointA.Y, -20});
            DataPoint dpB = new DataPoint(radarConfigured.SafetyArea.PointB.X, new Double[]{radarConfigured.SafetyArea.PointB.Y, -20});
            DataPoint dpC = new DataPoint(radarConfigured.SafetyArea.PointC.X, new Double[] { radarConfigured.SafetyArea.PointC.Y, -20 });
            DataPoint dpD = new DataPoint(radarConfigured.SafetyArea.PointD.X, new Double[] { radarConfigured.SafetyArea.PointD.Y, -20 });
            dpA.Label = "A";
            dpB.Label = "B";
            dpC.Label = "C";
            dpD.Label = "D";
            serieSA.Points.Add(dpA);
            serieSA.Points.Add(dpB);
            serieSA.Points.Add(dpC);
            serieSA.Points.Add(dpD);

I would like to obtain a figure like a rectangle using these points. i've tried usign this code

What I have tried:

C#
safetyAreaAnnotation = new PolygonAnnotation();
            safetyAreaAnnotation.ClipToChartArea = chartCartesian.ChartAreas[0].Name;
            //safetyAreaAnnotation.AnchorX = 10;
            //safetyAreaAnnotation.AnchorY = 20;
            PointF[] points = new PointF[4];
            points[0].X = (float)dpA.XValue;
            points[0].Y = (float)dpA.YValues[0] ;
            points[1].X = (float)dpB.XValue;
            points[1].Y = (float)dpB.YValues[0];
            points[2].X = (float)dpC.XValue;
            points[2].Y = (float)dpC.YValues[0];
            points[3].X = (float)dpD.XValue;
            points[3].Y = (float)dpD.YValues[0];
            byte[] type = new byte[4];
            type[0] = (byte)PathPointType.Start;
            type[1] = (byte)PathPointType.Line;
            type[2] = (byte)PathPointType.Line;
            type[3] = (byte)PathPointType.CloseSubpath;

            safetyAreaAnnotation.GraphicsPath=new System.Drawing.Drawing2D.GraphicsPath(points,type);  
           // //safetyAreaAnnotation.IsSizeAlwaysRelative = false;
           // //safetyAreaAnnotation.BackColor = Color.Red;
           safetyAreaAnnotation.AxisX = chartCartesian.ChartAreas[0].AxisX;
           safetyAreaAnnotation.AxisY = chartCartesian.ChartAreas[0].AxisY;
           safetyAreaAnnotation.AnchorDataPoint = serieSA.Points[0];
           // //safetyAreaAnnotation.AnchorX = 1;
           // //safetyAreaAnnotation.AnchorY = 20;
            chartCartesian.Annotations.Add(safetyAreaAnnotation);


But it doesn't work. Nothing is displayed in my chart. Maybe i should use something different to draw this polygon?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900