// Build the Chart private void CreateGraph_Chart(ZedGraphControl zg1, int iRight, int iWrong) { // get a reference to the GraphPane GraphPane myPane = zg1.GraphPane; // Make up some random data points myPane.RemoveAllCurve(); //string[] labels = new string[2]{"正确","错误"}; double[] y = new double[1] { iRight }; double[] y2 = new double[1] { iWrong }; // Generate a red bar with "Curve 1" in the legend BarItem myBar2 = myPane.AddBar("正确数", null, y, Color.Green); myBar2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Green); BarItem myBar = myPane.AddBar("错误数", null, y2, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); // Draw the X tics between the labels instead of // at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels //myPane.XAxis.Scale.TextLabels = labels; //// Set the XAxis to Text type //myPane.XAxis.Type = AxisType.Text; //// Fill the Axis and Pane backgrounds //myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); //myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); // Tell ZedGraph to refigure the // axes since the data have changed zg1.AxisChange(); this.zedGraphControl1.Refresh(); }
// Build the Chart private void CreateGraph_Chart(ZedGraphControl zg1) { // get a reference to the GraphPane GraphPane myPane = zg1.GraphPane; // Make up some random data points myPane.RemoveAllCurve(); DataRow[] rows = MemoryTable.typeMapTable.Select("minCount > count"); if (rows.Length <= 0) { return; } string[] labels = new string[rows.Length]; double[] y = new double[rows.Length]; double[] y2 = new double[rows.Length]; for (int i = 0; i < rows.Length; i++) { labels[i] = (string)rows[i]["productName"]; int minCount = int.Parse(rows[i]["minCount"].ToString()); if (minCount <= 0) { y[i] = 0.1; } else { y[i] = (double)minCount; } int count = int.Parse(rows[i]["count"].ToString()); if (count <= 0) { y2[i] = 0.1; } else { y2[i] = (double)count; } } // Generate a red bar with "Curve 1" in the legend BarItem myBar = myPane.AddBar("安全库存", null, y, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); // Generate a blue bar with "Curve 2" in the legend myBar = myPane.AddBar("当前库存", null, y2, Color.Blue); myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); // Draw the X tics between the labels instead of // at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels myPane.XAxis.Scale.TextLabels = labels; //// Set the XAxis to Text type //myPane.XAxis.Type = AxisType.Text; //// Fill the Axis and Pane backgrounds //myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); //myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); //myPane.Title.Text = "库存预警商品信息"; //myPane.XAxis.Title.Text = "商品名称"; //myPane.YAxis.Title.Text = "商品数量"; // Tell ZedGraph to refigure the // axes since the data have changed zg1.AxisChange(); this.zedGraphControl1.Refresh(); }
private void btnOk_Click(object sender, EventArgs e) { DateTime dtTime_start = this.dtpStart.Value; DateTime dtTime_end = this.dtpEnd.Value; if (DateTime.Compare(dtTime_end, dtTime_start) <= 0) { MessageBox.Show("时间段选择不正确!", "信息提示"); return; } string time_start = dtTime_start.ToString("yyyy-MM-dd HH:mm:ss"); string time_end = dtTime_end.ToString("yyyy-MM-dd HH:mm:ss"); string sqlSelect_check_record = "select record_id,create_time,info from check_record where create_time between '{0}' and '{1}'"; DataTable dtCheck_record = CsharpSQLiteHelper.ExecuteTable(sqlSelect_check_record, new object[2] { time_start, time_end }); int iStuden_count = 0; DataTable studentInfoTable = studentInfoCtl.getAllStudentInfo(); iStuden_count = studentInfoTable.Rows.Count; GraphPane myPane = this.zedGraphControl1.GraphPane; // Set the titles and axis labels myPane.Title.Text = "考勤率统计"; myPane.XAxis.Title.Text = "考勤时间"; myPane.YAxis.Title.Text = "出勤率"; // Make up some random data points double x, y; PointPairList list = new PointPairList(); if (dtCheck_record.Rows.Count > 0) { DataTable dt = new DataTable(); dt.Columns.Add("考勤时间"); dt.Columns.Add("出勤率(%)"); dt.Columns.Add("备注"); for (int i = 0; i < dtCheck_record.Rows.Count; i++) { string info = dtCheck_record.Rows[i]["info"].ToString(); string strCreate_time = dtCheck_record.Rows[i]["create_time"].ToString(); DateTime dtCreate_time = DateTime.Parse(strCreate_time); string record_id = dtCheck_record.Rows[i]["record_id"].ToString(); string sqlSelect_student_check_record = "select student_id from T_STUDENT_CHECK_INFO where record_id = '{0}'"; DataTable dtStudent_check_record = CsharpSQLiteHelper.ExecuteTable(sqlSelect_student_check_record, new object[1] { record_id }); int iChecked_count = dtStudent_check_record.Rows.Count; int check_percent = iChecked_count * 100 / iStuden_count; x = (double)new XDate(dtCreate_time); y = check_percent; list.Add(x, y); dt.Rows.Add(new object[3] { strCreate_time, check_percent.ToString(), info }); } // Generate a red curve with diamond // symbols, and "My Curve" in the legend myPane.RemoveAllCurve(); CurveItem myCurve = myPane.AddCurve("考勤率曲线", list, Color.Red, SymbolType.Diamond); // Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; // Tell ZedGraph to refigure the axes since the data // have changed this.zedGraphControl1.AxisChange(); this.zedGraphControl1.Refresh(); this.dataGridView1.Columns.Clear(); this.dataGridView1.DataSource = dt; this.dataGridView1.Columns[0].Width = 150; this.dataGridView1.Columns[1].Width = 120; this.dataGridView1.Columns[2].Width = 400; Debug.WriteLine("zde"); } else { MessageBox.Show("该段时间内没有考勤记录!", "信息提示"); } }