简体   繁体   中英

Label x-axis by days of the week

I am trying to visualise data with a chart. I have done for hours, need to do for days and weeks to compare. Here is a sample code for the how I visualise hourly, having problems doing the same thing for day like monday, tuesday down to sunday in the intervals. How can I do this for day intervals?

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

Try this:

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

etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM