按星期几标记 x 轴
本文关键字: | 更新日期: 2023-09-27 18:34:24
我正在尝试用图表可视化数据。我已经做了几个小时,需要做几天和几周才能比较。这是一个示例代码,用于我每小时可视化一次,在周一、周二到周日等日做同样的事情时遇到问题。如何每隔一天执行此操作?
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);
试试这个:
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";
等。。。