Exemple #1
0
        /// <summary>
        /// Рисование всех кривых
        /// </summary>
        private void DrawCurves()
        {
            // Подготовим большие массивы данных по осям X и Y
            double xmin = -20;
            double xmax = 20;

            // Поличество точек в полном массиве
            int count = 10000;

            // Массивы с координатами точек по X и Y
            double[] xlist = new double[count];
            double[] ylist = new double[count];

            // Шаг дискретизации
            double dx = (xmax - xmin) / count;

            // Заполним массив из большого количества элементов
            for (int i = 0; i < count; i++)
            {
                double currx = xmin + i * dx;

                xlist[i] = currx;
                ylist[i] = f(currx);
            }

            // Сначала нарисуем кривую по полноценным массивам
            PointPairList fullList = new PointPairList(xlist, ylist);

            DrawGraph(fullList, Color.Red);

            // Теперь воспользуемся классом FilteredPointList,
            // чтобы уменьшить количество отображаемых точек.
            // В конструктор класса передаются полноценные массивы
            FilteredPointList filteredList = new FilteredPointList(xlist, ylist);

            // Параметры фильтрации точек
            // Нас интересует только интервал от -15 до 15
            double filteredXMin = -15;
            double filteredXMax = 15;

            // Нам достаточно 20-ти точек
            int filteredCount = 20;

            // Установим параметры фильтрации
            filteredList.SetBounds(filteredXMin, filteredXMax, filteredCount);

            // Нарисуем кривую по отфильтрованным точкам
            DrawGraph(filteredList, Color.Blue);
        }
        private void ZedGraphControl1_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
        {
            if (AllowZoom)
            {
                IsZoomed = true;
                // The maximum number of point to displayed is based on the width of the graphpane, and the visible range of the X axis
                filteredDiameter.SetBounds(sender.GraphPane.XAxis.Scale.Min, sender.GraphPane.XAxis.Scale.Max, (int)sender.GraphPane.Rect.Width);

                ReZoomLineObjs();

                // This refreshes the graph when the button is released after a panning operation
                if (newState.Type == ZoomState.StateType.Pan)
                {
                    sender.Invalidate();
                }
            }
        }
        public void AddDataPoint(string diameter)
        {
            diameterList.Add(new DataListXY(new XDate(DateTime.Now), Convert.ToDouble(diameter)));

            double[] dblTime     = new double[diameterList.Count];
            double[] dblDiameter = new double[diameterList.Count];

            int index = 0;

            foreach (DataListXY item in diameterList.ToList())
            {
                dblTime[index]     = item.X;
                dblDiameter[index] = item.Y;
                index++;
            }

            if (IsHistorical)
            {
                if (!IsZoomed)
                {
                    filteredDiameter = new FilteredPointList(dblTime, dblDiameter);
                    filteredDiameter.SetBounds(this.zedGraphControl1.GraphPane.XAxis.Scale.Min, new XDate(DateTime.Now.AddMilliseconds(2)), (int)this.zedGraphControl1.GraphPane.Rect.Width);

                    this.zedGraphControl1.GraphPane.CurveList.Remove(diameterCurve);

                    diameterCurve = this.zedGraphControl1.GraphPane.AddCurve("Diameter", filteredDiameter, System.Drawing.Color.FromArgb(0, 153, 255), SymbolType.None);

                    //***********************//
                    //Adding the reference lines here updates the visual faster than adding them in a function
                    this.zedGraphControl1.GraphPane.GraphObjList.Remove(upperLimitLine);
                    if (this.zedGraphControl1.GraphPane.YAxis.Scale.Max >= Convert.ToDouble(upperLimitDiameter))
                    {
                        upperLimitLine            = new LineObj(System.Drawing.Color.FromArgb(255, 0, 0), this.zedGraphControl1.GraphPane.XAxis.Scale.Min, Convert.ToDouble(upperLimitDiameter), dblTime[dblTime.Count() - 1], Convert.ToDouble(upperLimitDiameter));
                        upperLimitLine.Line.Width = 2.0F;
                        this.zedGraphControl1.GraphPane.GraphObjList.Add(upperLimitLine);
                    }

                    this.zedGraphControl1.GraphPane.GraphObjList.Remove(lowerLimitLine);
                    if (this.zedGraphControl1.GraphPane.YAxis.Scale.Min <= Convert.ToDouble(lowerLimitDiameter))
                    {
                        lowerLimitLine            = new LineObj(System.Drawing.Color.FromArgb(255, 0, 0), this.zedGraphControl1.GraphPane.XAxis.Scale.Min, Convert.ToDouble(lowerLimitDiameter), dblTime[dblTime.Count() - 1], Convert.ToDouble(lowerLimitDiameter));
                        lowerLimitLine.Line.Width = 2.0F;
                        this.zedGraphControl1.GraphPane.GraphObjList.Add(lowerLimitLine);
                    }

                    this.zedGraphControl1.GraphPane.GraphObjList.Remove(nominalLine);
                    if (this.zedGraphControl1.GraphPane.YAxis.Scale.Min <= Convert.ToDouble(nominalDiameter) && this.zedGraphControl1.GraphPane.YAxis.Scale.Max >= Convert.ToDouble(nominalDiameter))
                    {
                        nominalLine            = new LineObj(System.Drawing.Color.FromArgb(64, 191, 67), this.zedGraphControl1.GraphPane.XAxis.Scale.Min, Convert.ToDouble(nominalDiameter), dblTime[dblTime.Count() - 1], Convert.ToDouble(nominalDiameter));
                        nominalLine.Line.Width = 2.0F;
                        this.zedGraphControl1.GraphPane.GraphObjList.Add(nominalLine);
                    }
                    //***********************//
                }
            }
            else
            {
                filteredDiameter = new FilteredPointList(dblTime, dblDiameter);
                filteredDiameter.SetBounds(new XDate(DateTime.Now.AddMilliseconds(-5000)), new XDate(DateTime.Now.AddMilliseconds(2)), (int)this.zedGraphControl1.GraphPane.Rect.Width);

                this.zedGraphControl1.GraphPane.CurveList.Remove(diameterCurve);

                diameterCurve = this.zedGraphControl1.GraphPane.AddCurve("Diameter", filteredDiameter, System.Drawing.Color.FromArgb(0, 153, 255), SymbolType.None);


                //***********************//
                //Adding the reference lines here updates the visual faster than adding them in a function
                this.zedGraphControl1.GraphPane.GraphObjList.Remove(upperLimitLine);
                if (this.zedGraphControl1.GraphPane.YAxis.Scale.Max >= Convert.ToDouble(upperLimitDiameter))
                {
                    upperLimitLine            = new LineObj(System.Drawing.Color.FromArgb(255, 0, 0), new XDate(DateTime.Now.AddMilliseconds(-5000)), Convert.ToDouble(upperLimitDiameter), this.zedGraphControl1.GraphPane.XAxis.Scale.Max, Convert.ToDouble(upperLimitDiameter));
                    upperLimitLine.Line.Width = 2.0F;
                    this.zedGraphControl1.GraphPane.GraphObjList.Add(upperLimitLine);
                }

                this.zedGraphControl1.GraphPane.GraphObjList.Remove(lowerLimitLine);
                if (this.zedGraphControl1.GraphPane.YAxis.Scale.Min <= Convert.ToDouble(lowerLimitDiameter))
                {
                    lowerLimitLine            = new LineObj(System.Drawing.Color.FromArgb(255, 0, 0), new XDate(DateTime.Now.AddMilliseconds(-5000)), Convert.ToDouble(lowerLimitDiameter), this.zedGraphControl1.GraphPane.XAxis.Scale.Max, Convert.ToDouble(lowerLimitDiameter));
                    lowerLimitLine.Line.Width = 2.0F;
                    this.zedGraphControl1.GraphPane.GraphObjList.Add(lowerLimitLine);
                }

                this.zedGraphControl1.GraphPane.GraphObjList.Remove(nominalLine);
                if (this.zedGraphControl1.GraphPane.YAxis.Scale.Min <= Convert.ToDouble(nominalDiameter) && this.zedGraphControl1.GraphPane.YAxis.Scale.Max >= Convert.ToDouble(nominalDiameter))
                {
                    nominalLine            = new LineObj(System.Drawing.Color.FromArgb(64, 191, 67), new XDate(DateTime.Now.AddMilliseconds(-5000)), Convert.ToDouble(nominalDiameter), this.zedGraphControl1.GraphPane.XAxis.Scale.Max, Convert.ToDouble(nominalDiameter));
                    nominalLine.Line.Width = 2.0F;
                    this.zedGraphControl1.GraphPane.GraphObjList.Add(nominalLine);
                }
                //***********************//
            }
        }