public Boolean AddData(PlotData Data) { if (Axes.Contains(Data.XAxis) && Axes.Contains(Data.YAxis)) { Plots.Add(Data); Data.XAxis.Info.Merge(Data.Data.Select(x => x.Item1).ToArray()); Data.YAxis.Info.Merge(Data.Data.Select(x => x.Item2).ToArray()); return(true); } else { return(false); } }
private static Canvas NewPlotLine(PlotData pd, Size sz) { //Plot Canvas plot = new Canvas() { Width = sz.Width, Height = sz.Height, Background = Brushes.Transparent }; double xScaler = pd.XAxis.Info.Range / sz.Width; double yScaler = pd.YAxis.Info.Range / sz.Height; PointCollection pc = new PointCollection(); for (int i = 0; i < pd.Data.Length; i++) { double xPart = ((pd.Data[i].Item1 - pd.XAxis.Info.Min) / pd.XAxis.Info.Range) * sz.Width; double yPart = (1.0d - ((pd.Data[i].Item2 - pd.YAxis.Info.Min) / pd.YAxis.Info.Range)) * sz.Height; pc.Add(new Point(xPart, yPart)); } //plotline if (pd.pType == PlotType.Line) { Polyline pl = new Polyline { Points = pc, Stroke = pd.PlotColor, StrokeThickness = pd.PlotThickness, Width = sz.Width, Height = sz.Height }; DocHelper.PutElementOn(pl, plot, sz.Width, sz.Height); } else if (pd.pType == PlotType.Dots) { const float width = 2; const float radius = width / 2; foreach (Point point in pc) { Ellipse ellipse = new Ellipse(); ellipse.SetValue(Canvas.LeftProperty, point.X - radius); ellipse.SetValue(Canvas.TopProperty, point.Y - radius); ellipse.Fill = pd.PlotColor; ellipse.Stroke = pd.PlotColor; ellipse.StrokeThickness = pd.PlotThickness; ellipse.Width = width; ellipse.Height = width; plot.Children.Add(ellipse); } } /* * //draw average line * double yAvg = y.Average(); * Line yAvgLine = new Line * { * X1 = 0, * X2 = plot.Width, * Y1 = plot.Height - ((yAvg - minY) / yScaler), * Y2 = plot.Height - ((yAvg - minY) / yScaler), * Stroke = Brushes.Red, * StrokeThickness = DocHelper.MM2Dibs(0.2), * StrokeStartLineCap = PenLineCap.Flat, * StrokeEndLineCap = PenLineCap.Flat * }; * * DocHelper.PutElementOn(yAvgLine, plot); * * * //simple linear regression * Tuple<double, double> simpleLinear = Fit.Line(x, y); * * double fit = GoodnessOfFit.RSquared(x.Select(x => simpleLinear.Item1 + simpleLinear.Item2 * x), y); * Line l = new Line * { * X1 = 0, * X2 = Width, * Y1 = (plot.Height - ((simpleLinear.Item2 - minY) / yScaler)), * Y2 = (plot.Height - ((((simpleLinear.Item1 * rangeX) + simpleLinear.Item2) - minY) / yScaler)), * Stroke = Brushes.Blue, * StrokeThickness = DocHelper.MM2Dibs(0.75) * }; * * plot.Children.Add(l); * //DocHelper.PutElementOn(l, content); */ return(plot); }