日期:2014-05-17 浏览次数:20999 次
private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.Chart1.Visible=true;
this.Chart1.Series.Clear();
string BDate=this.BDate.Value;
string EDate=this.EDate.Value;
DateTime dt1 = DateTime.Parse(BDate);
DateTime dt2 = DateTime.Parse(EDate);
TimeSpan ts = dt2 - dt1;
string[] arr = new string[(int)ts.TotalDays+1];
for(int i=0;i<arr.Length;i++)
{
arr[i] = dt1.AddDays(i).ToString("yyyy-MM-dd");
}
Series series;
ChartArea area = Chart1.ChartAreas[0];
foreach (ListItem ltM in CheckBoxList1.Items)
{
if (ltM.Selected)
{
string connection=this.Label2.Text= ltM.Text.ToString();
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con ;
cmd.CommandTimeout = int.Parse( System.Configuration.ConfigurationSettings.AppSettings["conntimeout"].Trim());
cmd.CommandType = CommandType.Text;
// string sql=SearchStr1(connection);
cmd.CommandText = SearchStr1(connection);
cmd.Connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataTable dt = new DataTable();
DataSet dt = new DataSet();
adapter.Fill(dt,"chart");
DataTable dat=new DataTable();
dat=dt.Tables[0];
int len=dat.Rows.Count;
string [] str1=new string[len];
double [] str2=new double[len];
for(int i=0;i<len;i++)
{
str1[i]=dat.Rows[i]["部門"].ToString();
str2[i]=Convert.ToDouble(dat.Rows[i]["出勤率"].ToString().Replace("%",""));
}
Chart1.Series.Add(connection);
Chart1.Series[connection].Type = SeriesChartType.Line;
Chart1.Series[connection].Points.DataBindXY(arr,str2);
int p=Chart1.Series[connection].Points.Count;
for(int i =0;i<Chart1.Series[connection].Points.Count;i++)
{
Chart1.Series[connection].Points[i].MarkerStyle = MarkerStyle.Circle;//設置折點的風格
// Chart1.Series[connection].Points[i].ShowInLegend = true;
}
Chart1.Series[connection].ToolTip = "X value \t= #VALX\nY value \t= #VALY{D}%";
}
}
}