public void UpdateReportPlots() { double maxTime = double.MinValue; double minTime = double.MaxValue; double maxValue = double.MinValue; double minValue = double.MaxValue; var plotModel = new PlotModel(); var plots = Plots.Where(p => p.Selected); foreach (var _timePlot in plots) { var lineSeries = new LineSeries(); var plotColor = _timePlot.PointColor; lineSeries.Color = OxyColor.FromArgb(plotColor.A, plotColor.R, plotColor.G, plotColor.B); lineSeries.MarkerFill = OxyColor.FromArgb(plotColor.A, plotColor.R, plotColor.G, plotColor.B); lineSeries.MarkerType = MarkerType.None; lineSeries.StrokeThickness = 1; lineSeries.DataFieldX = "Time"; lineSeries.DataFieldY = "Value"; var orderedPoints = _timePlot.PlotPoints .GroupBy(point => point.Time) .Select(group => group.First()) .OrderBy(point => point.Time) .ToList(); foreach (var _point in orderedPoints) { var time = _point.Time.TimeOfDay.TotalSeconds; var value = Convert.ToDouble(_point.Value); maxTime = maxTime < time ? time : maxTime; minTime = time < minTime ? time : minTime; maxValue = maxValue < value ? value : maxValue; minValue = value < minValue ? value : minValue; lineSeries.Points.Add(new DataPoint { X = time, Y = value }); } plotModel.Series.Add(lineSeries); } var dateTimeAxis = new TimeSpanAxis(AxisPosition.Bottom, minTime, maxTime, "Time"); dateTimeAxis.SetColors(); dateTimeAxis.AbsoluteMaximum = maxTime; dateTimeAxis.AbsoluteMinimum = minTime; plotModel.Axes.Add(dateTimeAxis); var linearAxis = new LinearAxis(AxisPosition.Left, minValue, maxValue, "Value"); linearAxis.SetColors(); linearAxis.AbsoluteMaximum = maxValue; linearAxis.AbsoluteMinimum = minValue; plotModel.Axes.Add(linearAxis); plotModel.SetColors(); ReportPlots = plotModel; }
public void PopulateBins(IEnumerable <double> samples, int numBins, string title) { var max = samples.Max(); var min = samples.Min(); var step = (max - min) / Convert.ToDouble(numBins); var binRange = Range.Double(min, max, step); var model = new PlotModel(title) { }; var s1 = new RectangleBarSeries { FillColor = OxyColors.CornflowerBlue }; foreach (var binMin in binRange) { var binMax = binMin + step; var binSamples = samples.Where(v => binMin <= v && v < binMax); var binCount = Convert.ToDouble(binSamples.Count()); s1.Items.Add(new RectangleBarItem { X0 = binMin, X1 = binMax, Y0 = 0, Y1 = binCount, }); } model.Series.Add(s1); model.PlotMargins = new OxyThickness(0, 30, 0, 0); var xMin = s1.Items.Min(b => b.X0); var xMax = s1.Items.Max(b => b.X1); if (xMin < xMax) { var xAxis = new LinearAxis(AxisPosition.Bottom, xMin, xMax, "Value"); xAxis.AbsoluteMinimum = xMin; xAxis.AbsoluteMaximum = xMax; xAxis.SetColors(); model.Axes.Add(xAxis); } var yMin = s1.Items.Min(b => b.Y0); var yMax = s1.Items.Max(b => b.Y1); if (yMin < yMax) { var yAxis = new LinearAxis(AxisPosition.Left, s1.Items.Min(b => b.Y0), s1.Items.Max(b => b.Y1), "Frequency"); yAxis.AbsoluteMinimum = s1.Items.Min(b => b.Y0); yAxis.AbsoluteMaximum = s1.Items.Max(b => b.Y1); yAxis.SetColors(); model.Axes.Add(yAxis); } model.SetColors(); HistogramModel = model; }