SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "server=172.11.29.111;uid=sa;pwd=sa;database=Transport";
sqlCon.Open();
string sqlStr = "select year(SmsTime),month(SmsTime), count(*) from AlarmSmsLog where datepart(year,SmsTime)='" + txt_Time.Text + "' group by year(SmsTime),month(SmsTime) ";
SqlDataAdapter da = new SqlDataAdapter(sqlStr, sqlCon);
DataTable dt = new DataTable();
da.Fill(dt);
sqlCon.Close();
Chart1.DataSource = dt;
if (DropDownList2.SelectedItem.Text == "折线图")
{
Chart1.Series[0].ChartType = SeriesChartType.Line;
}
if (DropDownList2.SelectedItem.Text == "柱状图")
{
Chart1.Series[0].ChartType = SeriesChartType.Column;
}
Chart1.ChartAreas[0].AxisX.Title = "月份"; //设置x轴标题
Chart1.ChartAreas[0].AxisY.Title = "统计次数";//设置x轴标题
Chart1.Series[0].XValueMember = dt.Columns[1].ToString();
Chart1.Series[0].YValueMembers = dt.Columns[2].ToString();