Пример #1
0
        // ------------------  CHARTING ROUTINES ---------------------

        // Set up the chart
        public void SetupChart()
        {
            // get a reference to the GraphPane
            var myPane = chartControl.GraphPane;

            // Set the Titles
            myPane.Title.Text = "Data logging using CmdMessenger";
            myPane.XAxis.Title.Text = "Time (s)";
            myPane.YAxis.Title.Text = "Voltage (v)";

            // Create data arrays for rolling points
            _analog1List = new RollingPointPairList(3000);
            _analog2List = new RollingPointPairList(3000);

            // Create a smoothened red curve 
            LineItem myCurve = myPane.AddCurve("Analog 1", _analog1List, Color.Red, SymbolType.None);
            myCurve.Line.IsSmooth = true;
            myCurve.Line.SmoothTension = 0.2f;

            // Create a smoothened blue curve 
            LineItem myCurve2 = myPane.AddCurve("Analog 2", _analog2List, Color.Blue, SymbolType.None);

            myCurve2.Line.IsSmooth = true;
            myCurve2.Line.SmoothTension = 0.2f;
            // Tell ZedGraph to re-calculate the axes since the data have changed
            chartControl.AxisChange();
        }
Пример #2
0
        private void AddDataToGraph(ZedGraphControl zg1, double xValue, double[] yValue1, double[] yValue2)
        {
            // Make sure that the curvelist has at least one curve
            if (zg1.GraphPane == null || zg1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem[]       curves = new LineItem[CurrentDevConfig.ChannelsSetting.Count];
            IPointListEdit[] lists  = new IPointListEdit[CurrentDevConfig.ChannelsSetting.Count];

            for (int i = 0; i < CurrentDevConfig.ChannelsSetting.Count; i++)
            {
                curves[i] = zg1.GraphPane.CurveList[i] as LineItem;
                lists[i]  = curves[i].Points as IPointListEdit;
                curves[i].Symbol.Fill.IsVisible = false;
                lists[i].Add(xValue, (i < CurrentDevConfig.ChannelsSetting.Count / 2) ? yValue1[i + 1] : yValue2[1 + i - (CurrentDevConfig.ChannelsSetting.Count / 2)]);
            }

            if (dataValues.Count % 10 == 0)
            {
                double minAxis = xValue - 22;
                zedGraphControl1.GraphPane.XAxis.Scale.Min = minAxis;
                zedGraphControl1.GraphPane.XAxis.Scale.Max = xValue + 3;
                zedGraphControl1.AxisChange();
                // force redraw
                zg1.Invalidate();
            }
        }
Пример #3
0
        private void zedGraphControl_MouseMove(object sender, MouseEventArgs e)
        {
            // Save the mouse location
            PointF mousePt = new PointF(e.X, e.Y);

            // Find the Chart rect that contains the current mouse location
            GraphPane pane = ((ZedGraphControl)sender).MasterPane.FindChartRect(mousePt);

            // If pane is non-null, we have a valid location.  Otherwise, the mouse is not
            // within any chart rect.
            if (pane != null)
            {
                double x, y;
                // Convert the mouse location to X, and Y scale values
                pane.ReverseTransform(mousePt, out x, out y);

                // 获取横纵坐标信息
                coordinateX.Text = x.ToString("f2");
                coordinateY.Text = y.ToString("f2");
                //coordinateX.Text = e.X.ToString();
                //coordinateY.Text = e.Y.ToString();
                //ColorRGB.Text = ;

                // 改变鼠标指针
                object nearestCurve;
                int    iNearest;
                bool   isSelected = zedGraphControl.GraphPane.FindNearestObject(mousePt, zedGraphControl.CreateGraphics(), out nearestCurve, out iNearest);
                if (isSelected)
                {
                    zedGraphControl.Cursor = Cursors.Hand;
                }
                else
                {
                    if (isStartDraw || isModify)
                    {
                        zedGraphControl.Cursor = Cursors.Cross;
                    }
                    else
                    {
                        zedGraphControl.Cursor = Cursors.Default;
                    }
                }

                // 拖拽修改折线
                if (isModify)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        if (TargetcurveItem != null)
                        {
                            IPointListEdit newlist = TargetcurveItem.Points as IPointListEdit;
                            newlist[TarfgetIndex].X = double.Parse(x.ToString("f2"));
                            newlist[TarfgetIndex].Y = double.Parse(y.ToString("f2"));
                            zedGraphControl.AxisChange();
                            zedGraphControl.Refresh();
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// ZedGraph 드로잉(X가 30이상이면 Shifting)
        /// </summary>
        /// <param name="zed">ZedGraphControl</param>
        /// <param name="current">X값</param>
        private void drawZed(ZedGraphControl zed, double current)
        {
            if (zed.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve = zed.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            IPointListEdit list = curve.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }

            list.Add(zedCnt, current);

            Scale xScale = zed.GraphPane.XAxis.Scale;

            if (zedCnt > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = zedCnt + xScale.MajorStep;
                xScale.Min = xScale.Max - 30.0;
            }

            zed.AxisChange();
            zed.Invalidate();
        }
Пример #5
0
        private void UpdatePrice(int noOfUpdate, CurveItem curve)
        {
            this.ShowMessage("Update " + noOfUpdate.ToString());
            IPointListEdit list    = curve.Points as IPointListEdit;
            int            lastPos = list.Count - 1;

            if (curve.GetType() == typeof(JapaneseCandleStickItem))
            {
                if (lastPos >= 0)
                {
                    (list as StockPointList).RemoveAt(lastPos);
                }
                for (int idx = Math.Max(0, lastPos); idx < myData.DateTime.Count; idx++)
                {
                    StockPt item = new StockPt(myData.DateTime[idx], myData.High.Values[idx], myData.Low.Values[idx],
                                               myData.Open.Values[idx], myData.Close.Values[idx], myData.Volume.Values[idx]);

                    (list as StockPointList).Add(item);
                }
            }
            else
            {
                if (lastPos >= 0)
                {
                    (list as PointPairList).RemoveAt(lastPos);
                }
                for (int idx = Math.Max(0, lastPos); idx < myData.DateTime.Count; idx++)
                {
                    PointPair item = new PointPair(myData.DateTime[idx], myData.Close.Values[idx]);
                    (list as PointPairList).Add(item);
                }
            }
        }
Пример #6
0
        public void DrawGraph(List <MyError> results)
        {
            //ve gia tri
            LineItem curve2_1 = DoThi_Error.GraphPane.CurveList[0] as LineItem;
            // LineItem curve2_2 = DoThi.GraphPane.CurveList[1] as LineItem;

            //init do thi.

            // Get the PointPairList
            IPointListEdit list21 = curve2_1.Points as IPointListEdit;

            list21.Clear();

            DoThi_Error.AxisChange();
            DoThi_Error.Invalidate();
            int i = 0;

            foreach (var item in results)
            {
                list21.Add(item.index, item.value);

                // đoạn chương trình thực hiện vẽ đồ thị
                Scale xScale = DoThi_Error.GraphPane.XAxis.Scale;
                i++;
            }

            // Vẽ đồ thị
            DoThi_Error.AxisChange();
            // Force a redraw
            DoThi_Error.Invalidate();

            //if (AppGlobol.IsAutoRun)
            //    DoThi_Error.GetImage().Save(AppGlobol.FolderPath + "/Error.png");
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_x1"></param>
        /// <param name="_y1"></param>
        /// <param name="_x2"></param>
        /// <param name="_y2"></param>
        private void draw(double _x1, double _y1)
        {
            if (zed.GraphPane.CurveList.Count <= 0)
            {
                return;
            }
            LineItem curve = zed.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            IPointListEdit list = curve.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }

            list.Add(_x1, _y1);


            if (_x1 > (zed.GraphPane.XAxis.Scale.Max - zed.GraphPane.XAxis.Scale.MajorStep + 20))
            {
                zed.GraphPane.XAxis.Scale.Max = _x1 + 120;
                // zed.GraphPane.XAxis.Scale.Min += 60;
            }
            zed.AxisChange();
            zed.Invalidate();
            zed.Refresh();
        }
Пример #8
0
 public void UpdateLineGraph(int id, double yValue)
 {
     try
     {
         GraphPane graphPane = this.masterPane.PaneList[0];
         if (graphPane.CurveList.Count <= 0)
         {
             return;
         }
         LineItem lineItem = graphPane.CurveList[0] as LineItem;
         if (lineItem == null)
         {
             return;
         }
         IPointListEdit pointListEdit = lineItem.Points as IPointListEdit;
         if (pointListEdit == null)
         {
             return;
         }
         pointListEdit[id].Y = yValue;
         graphPane.AxisChange();
         this.graph.Invalidate();
     }
     catch
     {
         throw new Exception("While updating data graph");
     }
 }
Пример #9
0
        // ------------------  CHARTING ROUTINES ---------------------

        // Set up the chart
        public void SetupChart()
        {
            // get a reference to the GraphPane
            var myPane = chartControl.GraphPane;

            // Set the Titles
            myPane.Title.Text       = "Data logging using CmdMessenger";
            myPane.XAxis.Title.Text = "Time (s)";
            myPane.YAxis.Title.Text = "Voltage (v)";

            // Create data arrays for rolling points
            _analog1List = new RollingPointPairList(3000);
            _analog2List = new RollingPointPairList(3000);

            // Create a smoothened red curve
            LineItem myCurve = myPane.AddCurve("Analog 1", _analog1List, Color.Red, SymbolType.None);

            myCurve.Line.IsSmooth      = true;
            myCurve.Line.SmoothTension = 0.2f;

            // Create a smoothened blue curve
            LineItem myCurve2 = myPane.AddCurve("Analog 2", _analog2List, Color.Blue, SymbolType.None);

            myCurve2.Line.IsSmooth      = true;
            myCurve2.Line.SmoothTension = 0.2f;
            // Tell ZedGraph to re-calculate the axes since the data have changed
            chartControl.AxisChange();
        }
Пример #10
0
        private void Draw(double x, double y)
        {
            LineItem curve = Graph.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            IPointListEdit list = curve.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }

            //double time = (Environment.TickCount - TickStart) / 1000;

            i++;
            list.Add(x, y);
            curve = Graph.GraphPane.AddCurve(null, list, Color.Blue, SymbolType.None);

            Scale xScale = Graph.GraphPane.XAxis.Scale;

            if (x > (xScale.Max - xScale.MajorStep))
            {
                xScale.Max = xScale.Max + xScale.MinorStep;
                xScale.Min = xScale.Max - 30;
            }

            Graph.AxisChange();
            Graph.Invalidate();
        }
Пример #11
0
 public void UpdateLineGraph(int serie, double time, double value)
 {
     try
     {
         GraphPane pane = masterPane.PaneList[0];
         if (pane.CurveList.Count > 0)
         {
             LineItem item = pane.CurveList[serie] as LineItem;
             if (item != null)
             {
                 IPointListEdit points = item.Points as IPointListEdit;
                 if (points != null)
                 {
                     points.Add(time, value);
                     if ((time > pane.XAxis.Scale.Max) || (pane.XAxis.Scale.Max > 10.0))
                     {
                         pane.XAxis.Scale.Max = time;
                         pane.XAxis.Scale.Min = pane.XAxis.Scale.Max - 10.0;
                     }
                     pane.AxisChange();
                     graph.Invalidate();
                 }
             }
         }
     }
     catch
     {
         throw new Exception("While updating data graph");
     }
 }
Пример #12
0
 public void UpdateLineGraph(int serie, double time, double value)
 {
     try
     {
         GraphPane graphPane = this.masterPane.PaneList[0];
         if (graphPane.CurveList.Count <= 0)
         {
             return;
         }
         LineItem lineItem = graphPane.CurveList[serie] as LineItem;
         if (lineItem == null)
         {
             return;
         }
         IPointListEdit pointListEdit = lineItem.Points as IPointListEdit;
         if (pointListEdit == null)
         {
             return;
         }
         pointListEdit.Add(time, value);
         if (time > graphPane.XAxis.Scale.Max || graphPane.XAxis.Scale.Max > 10.0)
         {
             graphPane.XAxis.Scale.Max = time;
             graphPane.XAxis.Scale.Min = graphPane.XAxis.Scale.Max - 10.0;
         }
         graphPane.AxisChange();
         this.graph.Invalidate();
     }
     catch
     {
         throw new Exception("While updating data graph");
     }
 }
Пример #13
0
        void AddDataPoint(double dataX)
        {
            // Make sure that the curvelist has at least one curve
            //确保CurveList不为空
            if (zedgraph.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the  first CurveItem in the graph

            //取Graph第一个曲线,也就是第一步:在 GraphPane.CurveList 集合中查找 CurveItem
            for (int idxList = 0; idxList < zedgraph.GraphPane.CurveList.Count; idxList++)
            {
                LineItem curve = zedgraph.GraphPane.CurveList[idxList] as LineItem;
                if (curve == null)
                {
                    return;
                }

                // Get the PointPairList
                //第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据

                IPointListEdit list = curve.Points as IPointListEdit;

                // If this is null, it means the reference at curve.Points does not
                // support IPointListEdit, so we won't be able to modify it

                if (list == null)
                {
                    return;
                }


                // Time is measured in seconds
                double time = (Environment.TickCount - tickStart) / 1000.0;
                // 3 seconds per cycle

                list.Add(time, dataX);

                // Keep the X scale at a rolling 30 second interval, with one

                // major step between the max X value and the end of the axis
                Scale xScale = zedgraph.GraphPane.XAxis.Scale;
                if (time > xScale.Max - xScale.MajorStep)
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = xScale.Max - 30.0;
                }
            }
            // Make sure the Y axis is rescaled to accommodate actual data
            //第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围


            zedgraph.AxisChange(); // Force a redraw
                                   //第四步:调用Form.Invalidate()方法更新图表


            zedgraph.Invalidate();
        }
Пример #14
0
        public void Draw(double data, double data1, double data2)
        {
            if (zedGraphControl.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve  = zedGraphControl.GraphPane.CurveList[0] as LineItem;
            LineItem curve1 = zedGraphControl.GraphPane.CurveList[1] as LineItem;
            LineItem curve2 = zedGraphControl.GraphPane.CurveList[2] as LineItem;

            if (curve == null)
            {
                return;
            }
            if (curve1 == null)
            {
                return;
            }

            IPointListEdit list  = curve.Points as IPointListEdit;
            IPointListEdit list1 = curve1.Points as IPointListEdit;
            IPointListEdit list2 = curve2.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }

            // Time is measured in seconds
            double time = (Environment.TickCount - TickStart) / 1000.0;

            list.Add(time, data); // Thêm điểm trên đồ thị
            list1.Add(time, data1);
            list2.Add(time, data2);

            Scale xScale = zedGraphControl.GraphPane.XAxis.Scale;
            Scale yScale = zedGraphControl.GraphPane.YAxis.Scale;

            // Tự động Scale theo trục x
            if (time > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 30;
            }

            // Tự động Scale theo trục y
            if (data > yScale.Max - yScale.MajorStep)
            {
                yScale.Max = data + yScale.MajorStep;
            }
            else if (data < yScale.Min + yScale.MajorStep)
            {
                yScale.Min = data - yScale.MajorStep;
            }

            zedGraphControl.AxisChange();
            zedGraphControl.Invalidate();
            zedGraphControl.Refresh();
        }
Пример #15
0
        /// <summary>
        /// 添加数据点
        /// </summary>
        /// <param name="curveName"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public virtual void AddXYPoint(string curveName, PointPair xypoint)
        {
            //---异步调用
            if (this.zedGraphControl_myChart.InvokeRequired)
            {
                this.zedGraphControl_myChart.Invoke((EventHandler)
                                                    (delegate
                {
                    //---增加坐标XY轴的点
                    IPointListEdit ip = this.zedGraphControl_myChart.GraphPane.CurveList[curveName].Points as IPointListEdit;
                    if (ip != null)
                    {
                        ip.Add(xypoint);

                        //---刷新显示
                        this.RefreshZedGraph();
                    }
                }));
            }
            else
            {
                //---增加坐标XY轴的点
                IPointListEdit ip = this.zedGraphControl_myChart.GraphPane.CurveList[curveName].Points as IPointListEdit;
                if (ip != null)
                {
                    ip.Add(xypoint);

                    //---刷新显示
                    this.RefreshZedGraph();
                }
            }
        }
Пример #16
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //make sure curvelist isnt empty
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            //get first curve in graph
            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            IPointListEdit list = curve.Points as IPointListEdit;

            if (addindex < portdata.Count)
            {
                list.Add(counter, (double)portdata[addindex]);

                addindex = addindex + 20;
                counter  = counter + .02;
            }


            zedGraphControl1.GraphPane.XAxis.Scale.Max = counter + 5;
            zedGraphControl1.GraphPane.XAxis.Scale.Min = zedGraphControl1.GraphPane.XAxis.Scale.Max - 10;
            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();
            zedGraphControl1.Refresh();
        }
Пример #17
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Make sure that the curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem xcurve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            LineItem ycurve = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            LineItem zcurve = zedGraphControl1.GraphPane.CurveList[2] as LineItem;

            if (xcurve == null || ycurve == null || zcurve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit xlist = xcurve.Points as IPointListEdit;
            IPointListEdit ylist = ycurve.Points as IPointListEdit;
            IPointListEdit zlist = zcurve.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (xlist == null || ylist == null || zlist == null)
            {
                return;
            }

            // Time is measured in seconds
            //double time = (Environment.TickCount - tickStart) / 1000.0;
            double time = a_page.gps_time / 1000.0;

            // 3 seconds per cycle
            //list.Add(time, Math.Sin(2.0 * Math.PI * time / 3.0));
            xlist.Add(time, a_page.cal_ax);
            ylist.Add(time, a_page.cal_ay);
            zlist.Add(time, a_page.cal_az);

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            //if (time > xScale.Max - xScale.MajorStep)
            //{
            xScale.Max = time + (double)numericUpDown1.Value / 8;
            xScale.Min = xScale.Max - (double)numericUpDown1.Value;
            //}
            if (xScale.Min < 0)
            {
                xScale.Min = 0;
            }

            // Make sure the Y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
        }
 ///<summary>
 ///Add a point list to the navigator
 ///</summary>
 public void PointListCreate(string name, IPointListEdit ptList)
 {
     if (zedGraphControl.GraphPane == null)
     {
         return;
     }
     PointListCreate(name, ptList, Color.Black);
 }
        private void Draw(float setpoint)
        {
            float intsetpoint = setpoint;

            // float intcurrent = current;

            // Debug.WriteLine($"DEBUG ZED GRAPH------------- {setpoint}, {current}");


            if (zed.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve = zed.GraphPane.CurveList[0] as LineItem;

            // LineItem curve1 = zed.GraphPane.CurveList[1] as LineItem;
            if (curve == null)
            {
                return;
            }
            //if (curve1 == null)
            //return;

            IPointListEdit list = curve.Points as IPointListEdit;

            // IPointListEdit list1 = curve1.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }
            // if (list1 == null)
            // return;
            double time = (Environment.TickCount - TickStart) / 1000.0;

            list.Add(time, intsetpoint);
            //  list1.Add(time, intcurrent);

            Scale xScale = zed.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                if (intMode == 1)
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = xScale.Max - 30.0;
                }
                else
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = 0;
                }
            }

            zed.AxisChange();
            zed.Invalidate();
        }
Пример #20
0
        public void draw(double setpoint1)
        {
            //make sure that curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return; // Kiểm tra việc khởi tạo các đường curve
            }
            LineItem curve1 = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

            //LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            if (curve1 == null)
            {
                return;
            }
            //if (curve2 == null)
            //    return;

            IPointListEdit list1 = curve1.Points as IPointListEdit;

            //IPointListEdit list2 = curve2.Points as IPointListEdit;
            if (list1 == null)
            {
                return;
            }
            //if (list2 == null)
            //    return;

            tickStart = tickStart + 1;
            double time = tickStart;

            //time = (Environment.TickCount - tickStart) / 500.0;

            list1.Add(time, setpoint1);// Đây chính là hàm hiển thị dữ liệu của mình lên đồ thị
            //list2.Add(time, setpoint1 + 20);

            //keep the X scale at a rolling 30 seconed interval, with one major step
            //between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                if (CheDo == _enCheDo.Compact)
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = xScale.Max - 30.0;
                }
                else
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = 0;
                }
            }

            //make sure the y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
        }
        private void Draw(float setpoint, float value2)
        {
            float intsetpoint = setpoint;
            float intcurrent  = value2;

            if (zed.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve  = zed.GraphPane.CurveList[0] as LineItem;
            LineItem curve1 = zed.GraphPane.CurveList[1] as LineItem;

            if (curve == null)
            {
                return;
            }
            if (curve1 == null)
            {
                return;
            }

            IPointListEdit list  = curve.Points as IPointListEdit;
            IPointListEdit list1 = curve1.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }
            if (list1 == null)
            {
                return;
            }
            double time = (Environment.TickCount - TickStart) / 1000.0;

            list.Add(time, intsetpoint);
            list1.Add(time, intcurrent);

            Scale xScale = zed.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                if (intMode == 1)
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = xScale.Max - 30.0;
                }
                else
                {
                    xScale.Max = time + xScale.MajorStep;
                    xScale.Min = 0;
                }
            }

            zed.AxisChange();
            zed.Invalidate();
        }
Пример #22
0
 /// <summary>
 /// 根据index来获取PointList
 /// </summary>
 /// <param name="index"></param>
 public IPointListEdit GetPointList(int index)
 {
     try
     {
         IPointListEdit iList = zed1.GraphPane.CurveList[index].Points as IPointListEdit;
         return(iList);
     }
     catch { return(null); }
 }
Пример #23
0
        // ------------------  CHARTING ROUTINES ---------------------

        /// <summary> Sets up the chart. </summary>
        public void SetupChart()
        {
            MasterPane masterPane = chartControl.MasterPane;
            masterPane.PaneList.Clear();

            // get a reference to the GraphPane

            _temperaturePane = new GraphPane(new Rectangle(5, 5, 890, 350),
                "Temperature controller",
                "Time (s)",
                "Temperature (C)");
            masterPane.Add(_temperaturePane);

            // Create data arrays for rolling points
            _analog1List = new RollingPointPairList(3000);
            _analog3List = new RollingPointPairList(3000);
            _analog1List.Clear();
            _analog3List.Clear();

            // Create a smoothened red curve for the current temperature
            LineItem myCurve1 = _temperaturePane.AddCurve("Current temperature", _analog1List, Color.Red, SymbolType.None);
            myCurve1.Line.Width = 2;
            myCurve1.Line.IsSmooth = true;
            myCurve1.Line.SmoothTension = 0.2f;


            // Create a smoothened blue curve for the goal temperature
            LineItem myCurve3 = _temperaturePane.AddCurve("Goal temperature", _analog3List, Color.Blue, SymbolType.None);
            myCurve3.Line.Width = 2;
            myCurve3.Line.IsSmooth = true;
            myCurve3.Line.SmoothTension = 0.2f;
            // Tell ZedGraph to re-calculate the axes since the data have changed
            chartControl.AxisChange();

            _heaterPane = new GraphPane(new Rectangle(5, 360, 890, 250),
                null,
                null,
                null);
            masterPane.Add(_heaterPane);
            
            _heaterList = new RollingPointPairList(3000);
            _heaterPwmList = new RollingPointPairList(3000);
            _heaterList.Clear();
            _heaterPwmList.Clear();

            // Create a red curve for the heater value
            LineItem heaterCurve = _heaterPane.AddCurve(null, _heaterList, Color.YellowGreen, SymbolType.None);
            heaterCurve.Line.Width = 2;
            heaterCurve.Line.IsSmooth = false;

            // Create a red curve for the current heater pwm value
            LineItem heaterPwmCurve = _heaterPane.AddCurve(null, _heaterPwmList, Color.Blue, SymbolType.None);
            heaterPwmCurve.Line.Width = 2;
            heaterPwmCurve.Line.IsSmooth = false;

            SetChartScale(0);
        }
Пример #24
0
        //画温度和光强曲线函数
        private void drawline(int channel, double data)
        {
            //确保curvelist不为空
            if (zedgraph.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem line;

            if (channel == 0)
            {
                //取graph第一个曲线,在GraphPane.CurveList集合中查找CurveItem,对应于温度曲线
                line = zedgraph.GraphPane.CurveList[0] as LineItem;
            }
            else
            {
                //得到对应于光强的曲线
                line = zedgraph.GraphPane.CurveList[1] as LineItem;
            }

            if (line == null)
            {
                return;
            }

            //在CurveItem中访问PointPairList,根据自己的需要增加新数据或修改已存在的数据
            IPointListEdit list = line.Points as IPointListEdit;

            //如果list为null,curve.Point不支持该类型

            if (list == null)
            {
                return;
            }

            //得到时间,加入list中的x轴和y轴
            double time = (Environment.TickCount - tickStart) / 1000.0;

            list.Add(time, data);

            //调整x轴的最大值与最小值
            Scale x = zedgraph.GraphPane.XAxis.Scale;

            if (time > x.Max - x.MajorStep)
            {
                x.Max = time + x.MajorStep;
                x.Min = x.Max - 30.0;
            }

            //force a redraw
            zedgraph.AxisChange();

            //调用方法方法更新图表
            zedgraph.Invalidate();
        }
Пример #25
0
        public void drawGraph()
        {
            // Make sure that the curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve1 = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            LineItem curve3 = zedGraphControl1.GraphPane.CurveList[2] as LineItem;

            if (curve1 == null || curve3 == null || curve2 == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list1 = curve1.Points as IPointListEdit;
            IPointListEdit list2 = curve2.Points as IPointListEdit;
            IPointListEdit list3 = curve3.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list1 == null || list2 == null || list3 == null)
            {
                return;
            }

            // Time is measured in seconds
            double time = (Environment.TickCount - tickStart) / 1000.0;

            // 3 seconds per cycle
            list1.Add(time, value1);
            list2.Add(time, value2);
            list3.Add(time, value3);

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 10.0;
            }

            // Make sure the Y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
            zedGraphControl1.IsShowPointValues = true;
            zedGraphControl1.PointValueFormat  = "0.000";
            zedGraphControl1.PointDateFormat   = "d";
        }
        ///<summary>
        ///Add a line to the navigator
        ///</summary>
        public void LineCreate(string name, IPointListEdit ptList)
        {
            if (zedGraphControl.GraphPane == null)
            {
                return;
            }
            var line = zedGraphControl.GraphPane.AddCurve(name, ptList, Color.Black, SymbolType.None);

            line.Tag = name;
        }
Пример #27
0
 private void trim(IPointListEdit points, int start)
 {
     if (points.Count > 0)
     {
         while (points[points.Count - 1].X > start)
         {
             points.RemoveAt(points.Count - 1);
         }
     }
 }
Пример #28
0
        private void Draw(double phase, double phase1)
        {
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve  = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            LineItem curve1 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;

            if (curve == null)
            {
                return;
            }
            if (curve1 == null)
            {
                return;
            }

            IPointListEdit siji = curve.Points as IPointListEdit;
            IPointListEdit loro = curve1.Points as IPointListEdit;

            if (siji == null)
            {
                return;
            }
            if (loro == null)
            {
                return;
            }

            double waktu = (Environment.TickCount - TickStart) / 10.0;

            siji.Add((waktu), phase);
            loro.Add((waktu), phase1);

            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            if (waktu > xScale.Max - xScale.MajorStep)
            {
                if (intMode == 1)
                {
                    xScale.Max = waktu + xScale.MajorStep;
                    xScale.Min = xScale.Max - 30.0;
                }
                else
                {
                    xScale.Max = waktu + xScale.MajorStep;
                    xScale.Min = 0;
                }

                zedGraphControl1.AxisChange();
                zedGraphControl1.Invalidate();
            }
        }
Пример #29
0
        private void draw()
        {
            LineItem       curve  = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            LineItem       curve1 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            IPointListEdit list   = curve.Points as IPointListEdit;
            IPointListEdit list1  = curve1.Points as IPointListEdit;

            list.Add(t, data_point);
            list1.Add(t, st_point);
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
            Scale yScale = zedGraphControl1.GraphPane.YAxis.Scale;

            LineItem       curve2 = zedGraphControl2.GraphPane.CurveList[0] as LineItem;
            IPointListEdit list2  = curve2.Points as IPointListEdit;

            list2.Add(t, control_point);
            Scale xScale1 = zedGraphControl2.GraphPane.XAxis.Scale;
            Scale yScale1 = zedGraphControl2.GraphPane.YAxis.Scale;

            t += 0.1f;

            if (t > xScale.Max - xScale.MajorStep)
            {
                xScale.Max  = t + xScale.MajorStep;
                xScale.Min  = xScale.Max - 30;
                xScale1.Max = t + xScale1.MajorStep;
                xScale1.Min = xScale1.Max - 30;
            }


            if (data_point > yScale.Max - yScale.MajorStep)
            {
                yScale.Max = data_point + yScale.MajorStep;
            }
            else if (data_point < yScale.Min + yScale.MajorStep)
            {
                yScale.Min = data_point - yScale.MajorStep;
            }
            if (control_point > yScale1.Max - yScale1.MajorStep)
            {
                yScale1.Max = control_point + yScale1.MajorStep;
            }
            else if (control_point < yScale1.Min + yScale1.MajorStep)
            {
                yScale1.Min = control_point - yScale1.MajorStep;
            }

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

            zedGraphControl2.AxisChange();
            zedGraphControl2.Invalidate();
            zedGraphControl2.Refresh();
        }
Пример #30
0
        private void Draw()
        {
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }
            // kiểm tra việc khởi tạo các đường curve
            // đưa vể điểm xuất phát

            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }
            // list các điểm
            IPointListEdit list = curve.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }
            // realtime được tính bắng ms
            realtime = (Environment.TickCount - tickStart) / 1000.0;

            list.Add(realtime, datanumber); // hàm hiển thị dữ liệu trên đồ thị



            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
            Scale yScale = zedGraphControl1.GraphPane.YAxis.Scale;

            // Tự động Scale theo trục x
            if (realtime > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = realtime + xScale.MajorStep;
                xScale.Min = xScale.Max - 30;
            }


            // Tự động Scale theo trục y
            if (datanumber > yScale.Max - yScale.MajorStep)
            {
                yScale.Max = datanumber + yScale.MajorStep;
            }
            else if (datanumber < yScale.Min + yScale.MajorStep)
            {
                yScale.Min = datanumber - yScale.MajorStep;
            }

            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();
            zedGraphControl1.Refresh();
        }
Пример #31
0
        // Vẽ đồ thị
        private void Draw()
        {
            LineItem curve = zGrphPlotData.GraphPane.CurveList[0] as LineItem;   //Khai báo đường cong từ danh sách đường cong đồ thị (kế thừa từ heap của dữ liệu ở Form_load)

            if (curve == null)
            {
                return;
            }
            LineItem curve2 = zGrphPlotData.GraphPane.CurveList[1] as LineItem;

            if (curve2 == null)
            {
                return;
            }
            IPointListEdit list = curve.Points as IPointListEdit;   //Khai báo danh sách dữ liệu cho đường cong đồ thị

            if (list == null)
            {
                return;
            }
            IPointListEdit list2 = curve2.Points as IPointListEdit;

            if (list2 == null)
            {
                return;
            }
            list.Add(realtime, setpoint);                        // Thêm điểm trên đồ thị
            list2.Add(realtime, measure);                        // Thêm điểm trên đồ thị

            Scale xScale = zGrphPlotData.GraphPane.XAxis.Scale;  //Giới hạn của đồ thị
            Scale yScale = zGrphPlotData.GraphPane.YAxis.Scale;

            if (enScroll == graphScroll.Scroll)
            {
                // Tự động Scale theo trục x
                if (realtime > xScale.Max - xScale.MajorStep)       //Nếu realtime lớn hơn Max x trừ đi 1 MajorStep (2 vạch lớn)
                {
                    xScale.Max = realtime + xScale.MajorStep;       //Tự dời đồ thị qua 1 MajorStep
                    xScale.Min = xScale.Max - 30;
                }
                // Tự động Scale theo trục y
                if (setpoint > yScale.Max - yScale.MajorStep)          //Nếu datas vượt quá giới hạn trừ 1 MajorStep
                {
                    yScale.Max = setpoint + yScale.MajorStep;          //Thì tăng giới hạn thêm 1 MajorStep
                }
                else if (setpoint < yScale.Min + yScale.MajorStep)
                {
                    yScale.Min = setpoint - yScale.MajorStep;
                }
                zGrphPlotData.AxisChange();                  //Thay đổi trục theo giá trị Scale
            }
            zGrphPlotData.Invalidate();                      //Mở khoá để và vẽ lại
        }
Пример #32
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            double time = (Environment.TickCount - tickStart) / 1000.0;

            // Make sure that the curvelist has at least one curve
            if (zg1.GraphPane == null || zg1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
            {
                return;
            }

            // Time is measured in seconds
            //double time = (Environment.TickCount - tickStart) / 1000.0;

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zg1.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 10.0;
            }

            // Make sure the Y axis is rescaled to accommodate actual data
            try
            {
                zg1.AxisChange();
            }
            catch
            {
            }
            // Force a redraw
            zg1.Invalidate();
        }
Пример #33
0
        private PointPair updateCurve(IPointListEdit list, double t, double v)
        {
            PointPair temp = new PointPair();

            list.Add(t, v);

            temp.X = list[0].X;
            temp.Y = t;

            return temp;
            /*
            for (int j = ZedGraphControl1.GraphPane.CurveList[k].NPts - 1; j > 0; j--)
            {
                ZedGraphControl1.GraphPane.CurveList[k].Points[j].Y = ZedGraphControl1.GraphPane.CurveList[k].Points[j - 1].Y;
            }

            //RawTextBox.AppendText(temp.ToString() + "-" + k.ToString() + ", ");
            ZedGraphControl1.GraphPane.CurveList[k].Points[0].X = 0;
            ZedGraphControl1.GraphPane.CurveList[k].Points[0].Y = v;
             */
        }
Пример #34
0
 private void trim(IPointListEdit points, int start)
 {
     if (points.Count > 0)
     {
         while (points[points.Count - 1].X > start)
         {
             points.RemoveAt(points.Count - 1);
         }
     }
 }
Пример #35
0
        private void CreateChart(ZedGraphControl zgc)
        {
            // TODO: Enhance the Graph display
            GraphPane myPane = zgc.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "Training Graph";
            myPane.XAxis.Title.Text = "Epochs";
            myPane.YAxis.Title.Text = "Least-Mean-Square Error";

            RollingPointPairList listTraining = new RollingPointPairList(ptsMax);
            RollingPointPairList listValidation = new RollingPointPairList(ptsMax);
            RollingPointPairList listSavepoint = new RollingPointPairList(ptsMax);
            RollingPointPairList currentSavepointList = new RollingPointPairList(ptsMax);

            // Add a curve
            LineItem curve;

            // Training
            curve = myPane.AddCurve("Training Set", ptsTraining, Color.Red, SymbolType.Diamond);
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 4;
            this.ptsTraining = curve.Points as IPointListEdit;
            // trainingCurve.Line.IsSmooth = true;
            // trainingCurve.Line.SmoothTension = 0.5F;

            // Validation
            curve = myPane.AddCurve("Validation Set", ptsValidation, Color.Blue, SymbolType.Diamond);
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 4;
            this.ptsValidation = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            // Savepoints
            curve = myPane.AddCurve("Savepoints Mark", ptsSavepoints, Color.DarkGreen, SymbolType.Circle);
            curve.Symbol.Fill = new Fill(Color.DarkGreen);
            curve.Symbol.Size = 4;
            curve.Line.IsVisible = false;
            this.ptsSavepoints = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            // Current Savepoint
            curve = myPane.AddCurve(String.Empty, currentSavepointList, Color.LimeGreen, SymbolType.Circle);
            curve.Symbol.Fill = new Fill(Color.LimeGreen);
            curve.Symbol.Size = 8;
            curve.Line.IsVisible = false;
            this.ptsCurrentSavepoint = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            // Set automatic scales adjustments
            myPane.XAxis.Scale.MinAuto = true;
            myPane.XAxis.Scale.MaxAuto = true;
            myPane.YAxis.Scale.MinAuto = true;
            myPane.YAxis.Scale.MaxAuto = true;
            myPane.XAxis.Scale.MagAuto = true;
            myPane.YAxis.Scale.MagAuto = true;

            // Fill the axis background with a color gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0F);

            // Calculate the Axis Scale Ranges
            zgc.AxisChange();
        }
Пример #36
0
        private void CreateChart(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "Training Graph";
            myPane.XAxis.Title.Text = "Epochs";
            myPane.YAxis.Title.Text = "Least-Mean-Square Error";

            RollingPointPairList trainingList = new RollingPointPairList(1200);
            RollingPointPairList validationList = new RollingPointPairList(1200);
            RollingPointPairList savepointList = new RollingPointPairList(1200);
            RollingPointPairList currentSavepointList = new RollingPointPairList(1200);

            // Add a curve
            LineItem curve;

            curve = myPane.AddCurve("Training Set", trainingList, Color.Red, SymbolType.Diamond);
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 4;
            this.m_trainingPoints = curve.Points as IPointListEdit;
            // trainingCurve.Line.IsSmooth = true;
            // trainingCurve.Line.SmoothTension = 0.5F;

            curve = myPane.AddCurve("Validation Set", validationList, Color.Blue, SymbolType.Diamond);
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 4;
            this.m_validationPoints = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            curve = myPane.AddCurve("Savepoints Mark", savepointList, Color.DarkGreen, SymbolType.Circle);
            curve.Symbol.Fill = new Fill(Color.DarkGreen);
            curve.Symbol.Size = 4;
            curve.Line.IsVisible = false;
            this.m_savePoints = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            curve = myPane.AddCurve(String.Empty, currentSavepointList, Color.LimeGreen, SymbolType.Circle);
            curve.Symbol.Fill = new Fill(Color.LimeGreen);
            curve.Symbol.Size = 8;
            curve.Line.IsVisible = false;
            this.m_currentSavepoint = curve.Points as IPointListEdit;
            // validationCurve.Line.IsSmooth = true;
            // validationCurve.Line.SmoothTension = 0.5F;

            myPane.XAxis.Scale.MinAuto = true;
            myPane.XAxis.Scale.MaxAuto = true;
            myPane.YAxis.Scale.MinAuto = true;
            myPane.YAxis.Scale.MaxAuto = true;
            myPane.XAxis.Scale.MagAuto = true;
            myPane.YAxis.Scale.MagAuto = true;

            // Fill the axis background with a color gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0F);

            // Calculate the Axis Scale Ranges
            zgc.AxisChange();
        }