Drawing arcs and lines on Polar chart.

SankaUD

Member
Joined
May 17, 2018
Messages
19
Programming Experience
1-3
Hi All,

Another questions related to Polar chart control. I want to draw two lines crossing certain values in polar chart and calculate the angle between line, then plot arc to indicate the angle and text to indicate value of the angle. how can I do this. any help much appriciated.
1590488622911.png

Cheers.
 
What have you tried, thought of, attempted since posting?
I have done most of the coding except for this drawing part on the polar chart. I even can draw the two lines using two series that goes through the calculated points. But not sure if that’s the best way of doing it. I’m not a pro programmer. I can post my code if you please.
 
That would probably be helpful. For starters, are you using the MSChart control, or something else from another vendor? What does their documentation say regarding what decorations/labels your can put on the generated charts?
 
Following function adds series to the chart. and inside of a class.

C#:
public Series AddSeriesToChart(string _SName, Color _SColour, string _cp1, string _cp2)
        {
            List<double> _cp1List = new List<double>();
            List<double> _GAL1 = GA.ToList();
            _cp1List = IDataTable.Rows.OfType<DataRow>().Select(dr => dr.Field<double>(_cp1)).ToList();


            for (int i = 0; i < _GAL1.Count; i++)
            {
                _GAL1[i] = _GAL1[i] * -1;
            }

            List<double> _cp2List = new List<double>();
            _cp2List = IDataTable.Rows.OfType<DataRow>().Select(dr => dr.Field<double>(_cp2)).ToList();
            _cp2List.Reverse();

            List<double> _GAL2 = GAngles.ToList();
            _GAL2.Reverse();

            _cp1List.AddRange(_cp2List);
            _GAL1.AddRange(_GAL2);

            Series _series = new Series
            {
                BorderWidth = 2,
                Color = _SColour
            };

            for (int i = 0; i < _GAL1.Count; i++)
            {
                _series.Points.AddXY(_GAL1[i], _cp1List[i]);
            }

            return _series;

And below plots the chart and inside of main application.

C#:
private void PlotPolarChart()
        {
            try
            {
                string[] AngleNames = { "0", "15", "30", "45", "60", "75", "90", "105", "120", "135", "150", "165", "180",
                "165", "150", "135", "120", "105", "90", "75", "60", "45", "30", "15" };

                int startOffset = 15;
                int endOffset = 15;

                Chart chrt = lvPolarPlot;
                chrt.Series.Clear();
                chrt.AntiAliasing = AntiAliasingStyles.All;
                chrt.TextAntiAliasingQuality = TextAntiAliasingQuality.High;

                ChartArea ca = chrt.ChartAreas[0];

                ca.Name = "Polar Plot";

                foreach (string AngleName in AngleNames)
                {
                    CustomLabel AngleLabel = new CustomLabel(startOffset, endOffset, AngleName, 0, LabelMarkStyle.None);
                    lvPolarPlot.ChartAreas[0].AxisX.CustomLabels.Add(AngleLabel);
                    startOffset += 15;
                    endOffset += 15;
                }

                ca.AxisY.LabelStyle.Angle = 0;
                ca.AxisX.Crossing = -180;

                Series _s1 = PViewer.AddSeriesToChart("a0a1", Color.Blue, "a0", "a1");               
                _s1.ChartArea = ca.Name;                           
                _s1.ChartType = SeriesChartType.Polar;
                lvPolarPlot.Series.Add(_s1);

                Series _s2 = PViewer.AddSeriesToChart("b9b2", Color.Red, "b9", "b2");
                _s2.ChartArea = ca.Name;
                _s2.ChartType = SeriesChartType.Polar;
                lvPolarPlot.Series.Add(_s2);

            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.ToString(), "Error");
            }
 
Back
Top Bottom