按星期几标记x轴

时间:2012-05-17 14:06:50

标签: c# .net winforms charts

我正在尝试使用图表可视化数据。我做了几个小时,需要做几天和几周的比较。这是一个示例代码,用于说明我每小时的可视化方式,在星期一,星期二到星期日等间隔内有问题做同样的事情。我如何在一天的间隔内完成这项工作?

chart1.ChartAreas.Add("area");
chart1.ChartAreas["area"].AxisX.Minimum = 0;
chart1.ChartAreas["area"].AxisX.Maximum = 24;
chart1.ChartAreas["area"].AxisX.Interval = 1;
chart1.ChartAreas["area"].AxisY.Minimum = 0;
chart1.ChartAreas["area"].AxisY.Maximum = intYAxisMax;
chart1.ChartAreas["area"].AxisY.Interval= 10;

chart1.Series.Add("Electric");
chart1.Series.Add("Gas");

chart1.Series["Electric"].Color = Color.Red;
chart1.Series["Gas"].Color = Color.Green;

chart1.ChartAreas["area"].AxisX.Title = "Hours";
chart1.ChartAreas["area"].AxisY.Title = "KW/H";

Title objTest = new Title("Daily Data Usage");
chart1.Titles.Add(objTest);

Legend objLegend = new Legend("Testing");
chart1.Legends.Add(objLegend);

//chart1.Series["Electric"].Points.AddXY(20 , 203);
//chart1.Series["Gas"].Points.AddXY(11, 70);

1 个答案:

答案 0 :(得分:1)

试试这个:

chart1.Series["Electric"].IsXValueIndexed = true;

//Add data
chart1.Series["Electric"].Points.AddXY(1, 203);
chart1.Series["Electric"].Points.AddXY(2, 70);

//X-axis labels
chart1.Series["Electric"].Points[0].AxisLabel = "Sunday";
chart1.Series["Electric"].Points[1].AxisLabel = "Monday";

等...