[英]Divide X-axis of a graph in weeks in windows form visual studio 2010
我想在图表上显示一年(2013-14)的数据,并希望在几周(约52列)的windows窗体Visual Studio 2010中破坏我的x轴。请告诉我如何设置它。
The code below 下面的代码
Please note: The week number can be calculated in various ways, depending on the culture info on your machine. 请注意:周数可以通过多种方式计算,具体取决于您计算机上的区域性信息。 If you need, you can always set the values of
CalendarWeekRule
and FirstDayOfWeek
to the ones you actually want. 如果需要,可以始终将
CalendarWeekRule
和FirstDayOfWeek
的值设置为实际所需的值。
using System.Windows.Forms.DataVisualization.Charting;
using System.Globalization;
private void setChart(int Year)
{
bool showAsDate = true;
var s = new Series(year.ToString() );
s.ChartType = SeriesChartType.Column;
var d = new DateTime(year, 01, 01);
int weekday = (int)d.DayOfWeek;
int maxDays = new DateTime(year, 12, 31).DayOfYear;
Random R = new Random();
for (int i = 0; i < maxDays ; i++)
{
s.Points.AddXY(d.AddDays(i), R.Next(100) - 50);
}
chart1.Series[0].Points.Clear();
chart1.Series.Clear();
chart1.Series.Add(s);
if (showAsDate )
{
chart1.Series[0].XValueType = ChartValueType.DateTime;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MM-dd";
chart1.ChartAreas[0].AxisX.Interval = 7;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
chart1.ChartAreas[0].AxisX.IntervalOffset = 0;
}
else
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
Calendar cal = dfi.Calendar;
for (int i = 0; i < maxDays ; i++)
{
chart1.Series[0].Points[i].AxisLabel =
cal.GetWeekOfYear(d.AddDays(i),
dfi.CalendarWeekRule, dfi.FirstDayOfWeek).ToString();
chart1.ChartAreas[0].AxisX.IntervalOffset = 2 - weekday;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.