private void Read()
        {
            _isReading = !_isReading;

            Task.Factory.StartNew(() =>
            {
                _timeStamp = DateTime.Now;

                Values1.Clear();
                Values2.Clear();
                Values3.Clear();

                while (_isReading)
                {
                    Thread.Sleep(100);

                    var newItems = GetNext(1);

                    Values1.AddRange(newItems.Select(x => x.Series1Lecture));
                    Values2.AddRange(newItems.Select(x => x.Series2Lecture));
                    Values3.AddRange(newItems.Select(x => x.Series3Lecture));

                    if (_refreshAxis)
                    {
                        var lastPoint = Values3.DefaultIfEmpty(new LecturePoint()).Last().TimeSpan;
                        To            = lastPoint.Ticks;
                        From          = lastPoint.Ticks - TimeSpan.FromSeconds(10).Ticks;
                    }
                }
            });
        }
Beispiel #2
0
 public void AreNotEqual(Values1 actual)
 {
     Assert.NotNull(actual);
     Assert.AreNotEqual(FieldType0, actual.FieldType0);
     Assert.AreNotEqual(FieldType1, actual.FieldType1);
     Assert.AreNotEqual(PropertyType, actual.PropertyType);
 }
Beispiel #3
0
 public GraphViewModel(ICollection <KeyValuePair <int, double> > values0, ICollection <KeyValuePair <int, double> > values1, Brush stroke0, Brush stroke1, string title, string decorate, double min, double max, string xtext)
 {
     if (values0 != null && values0.Count > 0)
     {
         this.Values0 = new DoubleCollection();
         foreach (var v0 in values0)
         {
             Values0.Add(v0.Value);
         }
     }
     if (values1 != null && values1.Count > 0)
     {
         this.Values1 = new DoubleCollection();
         foreach (var v1 in values1)
         {
             Values1.Add(v1.Value);
         }
     }
     Stroke0  = stroke0;
     Stroke1  = stroke1;
     Title    = title;
     Decorate = decorate;
     Minimum  = min;
     Maximum  = max;
     XText    = xtext;
 }
Beispiel #4
0
        /// <summary>
        /// Process ra data
        /// </summary>
        /// <param name="entry"></param>
        private void ProcessValues1(MonitorEntry entry)
        {
            var date  = entry.Datetime.ToLocalTime();
            var point = new PointModel {
                DateTime = date, Value = 0, Set = ChartValueSet.Values1
            };
            var msg = entry.Message.Split(',');

            double.TryParse(msg[2], out var steps);

            if (IsZeroBased)
            {
                var zero = Conversions.Deg2ArcSec(90.0) * raStepsPerSecond;
                steps -= zero;
            }

            switch (Scale)
            {
            case ChartScale.Degrees:
                point.Value = Conversions.ArcSec2Deg(steps / raStepsPerSecond);
                break;

            case ChartScale.Arcsecs:
                point.Value = steps / raStepsPerSecond;
                break;

            case ChartScale.Steps:
                point.Value = steps;
                break;

            default:
                return;
            }
            if (IsLogging)
            {
                ChartLogging.LogPoint(BaseLogName, ChartType.Plot, point);
            }

            Values1.Add(point);
            if (Values1.Count > MaxPoints)
            {
                Values1.RemoveAt(0);
            }

            var item = TitleItems.FirstOrDefault(x => x.TitleName == Values1Title);

            if (item == null)
            {
                return;
            }
            item.Value = point.Value;
        }
Beispiel #5
0
        private void button2_Click(object sender, RoutedEventArgs e) //wykres
        {
            Values1.Clear();
            Values2.Clear();
            Chart1.Update();

            N = Convert.ToInt32(tb1.Text);
            A = Convert.ToDouble(tb2.Text);
            P = Convert.ToDouble(tb3.Text);
            if ((N == 0 && A == 0) || (N == 0 && P == 0) || (A == 0 && P == 0) || (A == 0 && P == 0 && N == 0))
            {
                MessageBox.Show("Wprowadzone dane nie są odpowiedniego formatu.", "Zły format danych wejściowych");
            }

            else if (N != 0 && A != 0 && P != 0)
            {
                MessageBox.Show("Jedno pole powinno zostać puste.", "Zły format danych wejściowych");
            }


            else if (P == 0) //wykres P(A=const,N)
            {
                N2 = Convert.ToInt32(tb5.Text);
                if (N >= N2)
                {
                    MessageBox.Show("Podany przedział liczbowy nie istnieje.", "Zły format danych wejściowych");
                }
                OsY.Title = "P(A,N)";
                OsX.Title = "N";
                SepY.Step = 0.1;
                SepX.Step = (int)(N2 / 22) + 1;
                DrawChart(1, CalculateNseries(N, N2), CalculatePseries(A, N, N2));
                DataContext = this;
            }

            else if (N == 0) // wykres N(P=const, A)
            {
                A2 = Convert.ToDouble(tb6.Text);
                if (A >= A2)
                {
                    MessageBox.Show("Podany przedział liczbowy nie istnieje.", "Zły format danych wejściowych");
                }
                OsY.Title = "N(P,A)";
                OsX.Title = "A";
                SepY.Step = 1;
                SepX.Step = 0.5;
                DrawChart(2, CalculateAseries(A, A2, P), CalculateNseriesY(CalculateAseries(A, A2, P), P));
                DataContext = this;
            }
        }
Beispiel #6
0
 public void DrawChart(int series_index, List <double> xvalues, List <double> yvalues)
 {
     if (series_index == 1)
     {
         for (int i = 0; i < xvalues.Count(); i++)
         {
             Values1.Add(new ObservablePoint {
                 X = xvalues[i], Y = yvalues[i]
             });
         }
     }
     if (series_index == 2)
     {
         for (int i = 0; i < xvalues.Count(); i++)
         {
             Values2.Add(new ObservablePoint {
                 X = xvalues[i], Y = yvalues[i]
             });
         }
     }
 }
Beispiel #7
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.PathFigure0 = GetTemplateChild("PathFigure0") as PathFigure;
            this.SubPath     = GetTemplateChild("SubPath") as Path;
            title            = GetTemplateChild("Title") as TextBlock;
            Y0 = GetTemplateChild("Y0") as TextBlock;
            Y1 = GetTemplateChild("Y1") as TextBlock;
            Y2 = GetTemplateChild("Y2") as TextBlock;
            Y3 = GetTemplateChild("Y3") as TextBlock;
            Y4 = GetTemplateChild("Y4") as TextBlock;
            X0 = GetTemplateChild("X0") as TextBlock;
            X1 = GetTemplateChild("X1") as TextBlock;
            X2 = GetTemplateChild("X2") as TextBlock;
            X3 = GetTemplateChild("X3") as TextBlock;
            X4 = GetTemplateChild("X4") as TextBlock;

            if (Values0 == null || Values0.Count < 1)
            {
                return;
            }
            double bottom;
            double top;
            double labelStep;

            if (Values1 == null || Values1.Count < 1)
            {
                SubPath.Visibility = Visibility.Collapsed;
                var max = Values0.Max();
                var min = Values0.Min();
                if (max == min)
                {
                    min -= min * 0.1;
                    max += max * 0.1;
                }

                bottom = min - (max - min) * 0.1;
                top    = max + (max - min) * 0.1;
                bottom = bottom < Minimum ? Minimum : bottom;
                top    = top > Maximum ? Maximum : top;
                var center = (max + min) / 2;
                labelStep = (top - bottom) / 4;
            }
            else
            {
                SubPath.Visibility = Visibility.Visible;
                var max = Math.Max(Values0.Max(), Values1.Max());
                var min = Math.Min(Values0.Min(), Values1.Min());
                if (max == min)
                {
                    min -= min * 0.1;
                    max += max * 0.1;
                }
                bottom = min - (max - min) * 0.1;
                top    = max + (max - min) * 0.1;
                bottom = bottom < Minimum ? Minimum : bottom;
                top    = top > Maximum ? Maximum : top;
                var center = (max + min) / 2;
                labelStep = (top - bottom) / 4;
            }
            var pathFigure1 = ((((SubPath.Data as GeometryGroup).Children[0] as PathGeometry).Figures as PathFigureCollection)[0] as PathFigure);

            PathFigure0.Segments.Clear();
            pathFigure1.Segments.Clear();

            title.Text = Title;
            Y0.Text    = bottom.ToString("0.0") + FormatDecoration;
            Y1.Text    = (bottom + labelStep).ToString("0.0") + FormatDecoration;
            Y2.Text    = (bottom + 2 * labelStep).ToString("0.0") + FormatDecoration;
            Y3.Text    = (bottom + 3 * labelStep).ToString("0.0") + FormatDecoration;
            Y4.Text    = (bottom + 4 * labelStep).ToString("0.0") + FormatDecoration;

            if (!XText.IsNullorEmpty())
            {
                var xTexts = XText.Split(',');
                X0.Text = xTexts[0];
                X1.Text = xTexts[1];
                X2.Text = xTexts[2];
                X3.Text = xTexts[3];
                X4.Text = xTexts[4];
            }

            var actualMin = bottom;
            var actualMax = bottom + 4 * labelStep;

            var length      = actualMax - actualMin;
            var step        = 512 / (Values0.Count + 1);
            var actaulStart = GRAPH_ACTUALSTART - ((Values0[0] - actualMin) / length) * GRAPH_ACTUALHEIGHT;

            PathFigure0.StartPoint = new Windows.Foundation.Point(step, actaulStart);
            for (int i = 0; i < Values0.Count; i++)
            {
                var actaulY = GRAPH_ACTUALSTART - ((Values0[i] - actualMin) / length) * GRAPH_ACTUALHEIGHT;
                PathFigure0.Segments.Add(new LineSegment
                {
                    Point = new Windows.Foundation.Point(step * (i + 1), actaulY)
                });
            }
            if (Values1 != null && Values1.Count > 0)
            {
                var step1        = 512 / (Values1.Count + 1);
                var actaulStart1 = GRAPH_ACTUALSTART - ((Values1[0] - actualMin) / length) * GRAPH_ACTUALHEIGHT;
                pathFigure1.StartPoint = new Windows.Foundation.Point(step1, actaulStart1);
                for (int i = 0; i < Values1.Count; i++)
                {
                    var actaulY = GRAPH_ACTUALSTART - ((Values1[i] - actualMin) / length) * GRAPH_ACTUALHEIGHT;
                    pathFigure1.Segments.Add(new LineSegment
                    {
                        Point = new Windows.Foundation.Point(step1 * (i + 1), actaulY)
                    });
                }
            }
        }
Beispiel #8
0
 protected override int Evaluate()
 {
     return(Values1.Sum() + Values2.Sum());
 }
Beispiel #9
0
        public ChartsViewModel()
        {
            #region 趋势图
            var r = new Random();

            for (int i = 0; i < 20; i++)
            {
                Values1.Add(new ObservableValue(r.Next(0, 20)));
            }
            for (int i = 0; i < 20; i++)
            {
                Values2.Add(new ObservableValue(r.Next(0, 20)));
            }
            #endregion

            #region 饼图
            Func <ChartPoint, string> f = cp => { return($"值:{cp.Y},{cp.Participation.ToString("f2")}%"); };
            PieDataList = new SeriesCollection
            {
                new PieSeries
                {
                    Title  = "饼1",
                    Values = new ChartValues <ObservableValue> {
                        new ObservableValue(4)
                    },
                    DataLabels = true,
                    LabelPoint = f
                },
                new PieSeries
                {
                    Title  = "饼2",
                    Values = new ChartValues <ObservableValue> {
                        new ObservableValue(3)
                    },
                    DataLabels = true,
                    LabelPoint = f,
                    FontSize   = 18
                },
                new PieSeries
                {
                    Title  = "饼3",
                    Values = new ChartValues <ObservableValue> {
                        new ObservableValue(8)
                    },
                    DataLabels = true,
                    LabelPoint = f
                },
            };
            #endregion

            #region 柱状图
            SeriesCollection = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title    = "2015",
                    FontSize = 33,
                    Values   = new ChartValues <double> {
                        10.1245, 50.1245, 39.1245, 50, 78, 99
                    },
                }
            };

            SeriesCollection.Add(new ColumnSeries
            {
                Title  = "2016",
                Values = new ChartValues <double> {
                    11.1245, 56, 42.1245
                },
            });

            SeriesCollection[1].Values.Add(48d);
            SeriesCollection[0].Values.Add(49d);
            Labels = new[] { "柱1", "柱2", "柱3", "柱4", "柱5", "柱6", "柱7", "柱8", };
            //y轴值转为整数
            Formatter = value => value.ToString("f0");

            #endregion
        }