MS chart radar axis frequency

我与影子孤独终老i 提交于 2019-12-23 12:09:24

问题


I'd like to draw a radar chart using MS Chart control in a WinForms app.

This chart contains data for 1 day, I have data for every seconds, so I have 86 400 x-y value pairs. X axis contains dates, y my int values.

My test code is like this:

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);

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

            var iterDate = fromDate;
            var i = 0;

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

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

            chart1.Series["Default"].Points.DataBindXY(xValues, yValues);

            var dateLabelStyle = new LabelStyle();
            dateLabelStyle.Format = "HH:mm:ss";
            chart1.ChartAreas["Default"].AxisX.LabelStyle = dateLabelStyle;

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

            chart1.Series["Default"].IsXValueIndexed = true;
            chart1.Series["Default"].ChartType = SeriesChartType.Radar;
            chart1.Series["Default"]["RadarDrawingStyle"] = "Line";
            chart1.Series["Default"]["AreaDrawingStyle"] = "Circle";
            chart1.Series["Default"]["CircularLabelsStyle"] = "Horizontal";
            chart1.ChartAreas["Default"].Area3DStyle.Enable3D = false;

Result view is like this:

I think the reason of the 'black circle effect' is that it draws y axis for every 86 400 points. How can I set it to draw these axes only at every hours?

Labels (dates as I set) for x axes do not appear. How can I show them?

Thx in advance!

.net4/c#/winforms/vs2010


回答1:


You probably want to use a "Polar" plot instead of "Radar". Something like that will get you closer to what you want I think:

chart1.Series["Default"].ChartType = SeriesChartType.Polar;
chart1.Series[0]["PolarDrawingStyle"] = "Line";
// setup the X grid
chart1.ChartAreas["Default"].AxisX.MajorGrid.Enabled = true;
chart1.ChartAreas["Default"].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Hours;
chart1.ChartAreas["Default"].AxisX.MajorGrid.Interval = 1;
chart1.ChartAreas["Default"].AxisX.Crossing = 0;
// setupthe Y grid
chart1.ChartAreas["Default"].AxisY.MajorGrid.Enabled = true;



来源:https://stackoverflow.com/questions/6976730/ms-chart-radar-axis-frequency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!