1

I'm trying to get some pretty simple polar plotting going here in a sandbox app and am getting some very strange results. Basically, I'm trying to recreate the answer to this question (eventually it gets a bit more complicated, but if I can do this, I should be on my way).

Here's some code of how I'm setting it up.

List<DateTime> xValues = new List<DateTime>();
List<double> yValues = new List<double>();

DateTime now = new DateTime(2012, 3, 20, 11, 24, 24);
DateTime then = now.AddHours(2.0);

var iterDate = now;
var i = 0;

while (iterDate <= then)
{
    xValues.Add(iterDate);
    yValues.Add(i);

    iterDate = iterDate.AddSeconds(1.0);
    i++;
}

chart1.Series[0].ChartType = SeriesChartType.Polar;
chart1.Series[0].Points.DataBindXY(xValues, yValues);
chart1.Series[0].XValueType = ChartValueType.DateTime;
chart1.Series[0].IsXValueIndexed = true;

chart1.ChartAreas[0].AxisX.Minimum = now.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = then.ToOADate();

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
chart1.Series[0]["PolarDrawingStyle"] = "Line";
// setup the X grid
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 1;
chart1.ChartAreas[0].AxisX.Crossing = 0;
// setupthe Y grid
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
chart1.ChartAreas[0].Area3DStyle.Enable3D = false;

And it shows up as this: chart

2 main questions:

  1. Why is it jagged?
  2. Why does it start and end around the 12:44:24 grid marker if I set my crossing to 0?

Update:

If I change the line:

DateTime now = new DateTime(2012, 3, 20, 11, 24, 24);

to

DateTime now = new DateTime();

the chart shows as desired: intended chart

I don't understand this drastic of a change based on the start date.

Community
  • 1
  • 1
petejamd
  • 523
  • 1
  • 10
  • 14

2 Answers2

2

When you set the start date to new DateTime() its OADate equivalent is 0. ( So you set XAxis minimum to 0 ) X Axis Minimum and Maximum properties are used to specify a different angular scale ( if you are not using 0-360 ) . If you are putting data on XAxis your data should make sense to Chartcontrol to a draw polar graphs. I am not sure what your intentions are but you should normalize data correctly if you want to display it on a polar graph.


It starts at 11:24:24 not 12:44:24. You need to change the start and end date of your axis if you want to draw 24Hrs on your polar graphs.

var fromDate = new DateTime(DateTime.Now.Year,
         DateTime.Now.Month,
         DateTime.Now.Day,
         0,
         0,
         0);

var toDate = new DateTime(DateTime.Now.Year,
      DateTime.Now.Month,
      DateTime.Now.Day,
      23,
      59,
      59);

chart1.ChartAreas[0].AxisX.Minimum = fromDate.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = toDate.ToOADate();

Also use tooltips to understand the plotted data on your graph

chart1.Series[0].ToolTip = "#VALX{hh:mm tt} --- #VALY";
Quantbuff
  • 827
  • 7
  • 9
  • I see that the Major Grid starts at 11:24:24, however, the data isn't aligning with that. (the Y value should show 0) – petejamd Mar 20 '12 at 18:38
  • I'm not really sure what you mean by normalize. I can sure have my data be greater than zero and less than 360, but that doesn't plot correctly when i set those minimum and maximum dates. Any resources you could point me to? – petejamd Mar 21 '12 at 00:17
1

Posted this on MSDN Forums here, and received an acceptable answer.

There's something wrong with the controls apparently. So you need to not use DateTime as the X Value Type and set the labels manually.

petejamd
  • 523
  • 1
  • 10
  • 14