Пример #1
0
        private void DrawDiagram()
        {
            NewOverallStats main = this.Owner as NewOverallStats;
            //main.radDropDownList1.Se
            int machid = main.radDropDownList1.SelectedIndex;
            //int measure = main.radDropDownList2.SelectedItem.Index;

            var Diagramm = new Chart();

            string          connStr = Program.connStr;
            MySqlConnection conn    = new MySqlConnection(connStr);

            conn.Open();

            DateTime minDate = main.radDateTimePicker1.Value;
            DateTime maxDate = main.radDateTimePicker2.Value;


            var crits = String.Format("SELECT COUNT FROM `machine_stats` WHERE ((`Machine ID` = {7}) AND (`DateTime` >= '{0}') AND (`DateTime` <= '{1}') AND ((`Temp` >= '{2}') OR (`Vibr` >= '{3}') OR " +
                                      "(`Power` >= '{4}') OR (`Load` >= '{5}') OR (`Wtime` >= '{6}')))", minDate, maxDate, Program.critTemp, Program.critVibr, Program.critPow, Program.critLoad, Program.critTime, machid);
            MySqlCommand command1 = new MySqlCommand(crits, conn);
            string       CritC    = command1.ExecuteScalar().ToString();

            var dangs = String.Format("SELECT COUNT FROM `machine_stats` WHERE ((`Machine ID` = {12}) AND (`DateTime` >= '{0}') AND (`DateTime` <= '{1}') AND ((`Temp` BETWEEN '{2}' AND '{3}') OR (`Vibr` BETWEEN '{4}' AND '{5}') OR " +
                                      "(`Power` BETWEEN '{6}' AND '{7}') OR (`Load` BETWEEN '{8}' AND '{9}') OR (`Wtime` BETWEEN '{10}' AND '{11}')))", minDate, maxDate, Program.dangTemp, Program.critTemp, Program.dangVibr, Program.critVibr,
                                      Program.dangPow, Program.critPow, Program.dangLoad, Program.critLoad, Program.dangTime, Program.critTime, machid);
            MySqlCommand command2 = new MySqlCommand(crits, conn);
            string       DangC    = command2.ExecuteScalar().ToString();

            Diagramm.Series[0].Points.AddY(DangC);
            Diagramm.Series[0].Points.AddY(CritC);


            conn.Close();
        }
Пример #2
0
        private void fillChart()
        {
            //DataSet ds = new DataSet();
            //ds.Tables[0].Rows[0][0];
            //chart1.Series["Series1"].LegendText = "График XY";

            NewOverallStats main = this.Owner as NewOverallStats;         //Шняга для передачи данных между формами. Но нужно соответсвующуе элементы пабликами делать

            int           machid     = main.radDropDownList1.SelectedItem.Index;
            int           measure    = main.radDropDownList2.SelectedItem.Index;
            Machine       dummy      = Program.machineList[machid];
            List <string> DataToDraw = new List <string>();

            switch (measure)
            {
            case 0:
                DataToDraw = dummy.getTempLog();
                break;

            case 1:
                DataToDraw = dummy.getVibrLog();
                break;

            case 2:
                DataToDraw = dummy.getPowerLog();
                break;

            case 3:
                DataToDraw = dummy.getLoadLog();
                break;

            case 4:
                DataToDraw = dummy.getWorkTimeLog();
                break;
            }

            GraphPane pane = zedGraphControl1.GraphPane;

            pane.CurveList.Clear();

            //DateTime minDate = main.radDateTimePicker1.Value;
            //DateTime maxDate = main.radDateTimePicker2.Value;
            PointPairList list = new PointPairList();

            //double[] xvalues = new double[DataToDraw.Count];
            //double[] yvalues = new double[DataToDraw.Count];

            for (int i = 0; i < DataToDraw.Count; i++)
            {
                string[] couple   = DataToDraw[i].Split('\t');
                string[] parsedDT = couple[0].Split(' ');
                string[] parsedD  = parsedDT[0].Split('.');
                string[] parsedT  = parsedDT[1].Split(':');

                XDate dt = new XDate(Convert.ToInt32(parsedD[2]), Convert.ToInt32(parsedD[1]), Convert.ToInt32(parsedD[0]),
                                     Convert.ToInt32(parsedT[0]), Convert.ToInt32(parsedT[1]), Convert.ToInt32(parsedT[2]));

                list.Add(dt, float.Parse(couple[1]));

                /*
                 * if (i == 0) minDate = dt;
                 * if (i == DataToDraw.Count - 1) maxDate = dt;
                 */

                //s.Points.AddXY(dt, float.Parse(couple[1]));
            }

            LineItem myCurve = pane.AddCurve(main.radDropDownList2.SelectedItem.Text + " машины " + (machid + 1).ToString(), list, Color.Blue, SymbolType.None);

            pane.XAxis.Type         = AxisType.Date;
            pane.XAxis.Scale.Format = "dd.MM.yyyy HH:mm:ss";

            pane.XAxis.Scale.Min = main.radDateTimePicker1.Value.ToOADate();
            pane.XAxis.Scale.Max = main.radDateTimePicker2.Value.ToOADate();

            pane.XAxis.Title.Text = "Время";
            pane.YAxis.Title.Text = main.radDropDownList2.SelectedItem.Text;

            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();

            /*
             * chart1.Series.Clear();
             * chart1.Series.Add(s);
             *
             * chart1.Series[0].XValueType = ChartValueType.DateTime;
             * chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dd.mm.yyyy hh:mm:ss";
             * chart1.ChartAreas[0].AxisX.Interval = 15;
             * chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
             * //chart1.ChartAreas[0].AxisX.IntervalOffset = Auto;
             * chart1.ChartAreas[0].AxisX.Minimum = minDate.ToOADate();
             * chart1.ChartAreas[0].AxisX.Maximum = maxDate.ToOADate();
             */
        }