日期:2014-05-20 浏览次数:20675 次
这样子X轴倒是对的,Y轴所有列上都有一个数字0
//计算当月有几天
int intDayCount = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int i = 1; i < intDayCount; i++)
{
series.Points.AddXY(i, 0);
}
DataTable dt = new DataTable("Data");
dt.Columns.Add("Day", typeof(DateTime));
dt.Columns.Add("Val", typeof(int));
//数据库数据
dt.Rows.Add(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), 35);
dt.Rows.Add(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 5), 53);
dt.Rows.Add(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15), 25);
chart1.Series[0].ChartType = SeriesChartType.Column;
//柱状图
chart1.Series[0].Points.DataBindXY(dt.DefaultView, "Day", dt.DefaultView, "Val");
//格式化 按天数显示
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dd";
DataTable dt = new DataTable();
dt.Columns.Add("days");//改成你的时间字段
dt.Columns.Add("daysTrafficSum");//改成你的求和的别名字段