问题
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:
2 main questions:
- Why is it jagged?
- 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:
I don't understand this drastic of a change based on the start date.
回答1:
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";
回答2:
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.
来源:https://stackoverflow.com/questions/9790831/having-issues-with-plotting-polar-data-on-a-datetime-x-axis