0

I have a polar chart I created by chart control in my WinForms app. X axis type is Distance, Y axis type is Azimuth.

My problem is that I cannot set X,Y initial points i.e (0,0) at center, it always appears at different place. Just as shown in figure 1 enter image description here

As you see in the above figures, Azimuth value is Zero at 270 and 360 at 90, and Distance is 0 at 180 and 100 at 0. Here is the code I used to create polar chart.

public PolarChart()
    {
        this.WindowState = FormWindowState.Maximized;
        InitializeComponent();

        Series s0 = new Series("PolarChart");
        s0.Color = Color.Gray;
        s0.ChartType = SeriesChartType.Polar;
        s0.Points.AddXY(0, 0);
        chart1.Series.Add(s0);
        chart1.Series[0]["PolarDrawingStyle"] = "line";
        chart1.ChartAreas[0].AxisX.Minimum = 0;
        chart1.ChartAreas[0].AxisX.Maximum = 360;
        chart1.ChartAreas[0].AxisX.Interval = 30;
        chart1.ChartAreas[0].AxisY.Minimum = 0;
        chart1.ChartAreas[0].AxisY.Maximum = 100;
        chart1.ChartAreas[0].AxisY.Interval = 10;            
    }

 private void btnDisplay_Click(object sender, EventArgs e)
    {

        TextFieldParser reader = new TextFieldParser("LFPoints.txt");
        reader.Delimiters = new string[] { "," };
        reader.HasFieldsEnclosedInQuotes = true;
        string[] read = reader.ReadFields();
        try
        {

            Series S2 = new Series("Plot");
            S2.ChartType = SeriesChartType.Polar;
            S2.BorderColor = Color.Red;
            if (read != null)

                if (read.Length != 0)
                {
                    foreach (string other in read)
                    {
                        ComputeDistanceAngle(other, Base);
                        S2.Points.AddXY(Azimuth, Distance);
                    }
                    chart1.Series.Add(S2);
                    chart1.Series["LFPlot"]["PolarDrawingStyle"] = "marker";
                }
                else
                {
                    MessageBox.Show("No Graph to Plot");
                }
            else
                MessageBox.Show("No Graph to Plot");
        }
        catch (Exception)
        {

        }
    }

private void chart1_MouseMove(object sender, MouseEventArgs e)
    {
        var pos = e.Location;
        if (prevPosition.HasValue && pos == prevPosition.Value)
            return;
        tooltip.RemoveAll();
        prevPosition = pos;
        var results = chart1.HitTest(pos.X, pos.Y, false,
                                     ChartElementType.PlottingArea);
        foreach (var result in results)
        {
            if (result.ChartElementType == ChartElementType.PlottingArea)
            {
                var xVal = result.ChartArea.AxisX.PixelPositionToValue(pos.X);
                var yVal = result.ChartArea.AxisY.PixelPositionToValue(pos.Y);

                tooltip.Show("Azimuth = " + xVal + "\n"+" Distance = " + yVal, this.chart1,
                             pos.X, pos.Y - 15);
            }
        }
    }

After I tried a lot I came to know about "Crossing" property.

chart1.ChartAreas[0].AxisX.Crossing = 90;
chart1.ChartAreas[0].AxisY.Crossing = 0;

But I didn't get what i need. So please help me to plot the points in polar chart with X and Y points starting from center. Here is the link which exactly how I need my polar chart. enter link description here

I am using Visual Studio 2010.

Gopi
  • 236
  • 2
  • 6
  • 20
  • It looks as if you try to interact using mouse coordinates. This is __extremly tricky__. What exactly are you trying to do? For reading out & showing the values you should set the tooltips of the datapoints instead. Or do you mean that the graph is somehow looking wrong? – TaW May 24 '15 at 15:31
  • @TaW Graph co-ordinates are wrong. If I just want to plot 60degrees, at a distance of 100, Instead of placing at that point it is placing somewhere else. Just help me out this. – Gopi May 24 '15 at 15:37
  • I don't see your data. You need to ignore the things you try with the mouse, ok? do your series.points actually contain a point 0,0? – TaW May 24 '15 at 16:11
  • _If I just want to plot 60degrees, at a distance of 100_ Hm, I would have expected you want to plot where the data point to? – TaW May 24 '15 at 16:22
  • @TaW I think there is problem in showing the datapoints with mouse. It is showing different values other than I plot. Can you help me to fix this one. I came to know that I have to change the code in "chart1_MouseMove". – Gopi May 24 '15 at 16:26
  • Throw the mouse code away! You can't get it right the way you try. Add tooltip to your datapoints! And do have a look at the data! – TaW May 24 '15 at 16:33
  • If you are interested in why your mouse code can't work, have a look at [this post](http://stackoverflow.com/questions/29902288/how-to-draw-a-graph-in-chart-control-with-mouse/29904293?s=1|1.9707#29904293). But __do not use the code__! It was only for drawing on the chart. If all you want is display data value add the tooltips to the datapoints! See [here](http://stackoverflow.com/questions/29895445/c-sharp-user-interactive-graph-from-datagridview/29939620?s=4|0.1492#29939620) for an example! – TaW May 24 '15 at 16:44
  • @TaW Here I am using XY values, but not DataPoint. So how can I add Tooltip? Any Suggestions.. – Gopi May 24 '15 at 16:47

0 Answers0