protected void UpdatePlotConfiguration() { // "PlotName" { OxyPlotModel.Title = PlotModel.PlotConfiguration.PlotName; } // "Axes" { //remove deleted Axes first var toRemoveAxis = new List <OxyPlot.Axes.LinearAxis>(); foreach (OxyPlot.Axes.LinearAxis oxaxis in OxyPlotModel.Axes) { if (oxaxis.Position != AxisPosition.Bottom) { var axis = PlotModel.PlotConfiguration.Axes.FirstOrDefault(x => x.OxyAxis == oxaxis);//don't remove xaxis if (axis == null) { toRemoveAxis.Add(oxaxis); } } } foreach (OxyPlot.Axes.LinearAxis oxaxis in toRemoveAxis) { OxyPlotModel.Axes.Remove(oxaxis); } foreach (AxisDefinitionModel axis in PlotModel.PlotConfiguration.Axes) { //can't use FirstOrDefault as OxyPlot sets default to first axis OxyPlot.Axes.LinearAxis oxaxis = null; foreach (OxyPlot.Axes.LinearAxis oa in OxyPlotModel.Axes) { if ((AxisDefinitionModel)oa.Tag == axis) { oxaxis = oa; break; } } //OxyPlot.Axes.LinearAxis oxaxis = OxyPlotModel.Axes.FirstOrDefault(x => x.Tag == axis) as OxyPlot.Axes.LinearAxis; if (oxaxis == null) { var yAxis = new OxyPlot.Axes.LinearAxis { Position = ConvertAxisToOxyPlot(axis.AxisPosition), Title = axis.AxisTitle, Unit = axis.Unit, Key = axis.Key }; yAxis.Tag = axis; OxyPlotModel.Axes.Add(yAxis); } else { //update oxaxis.Position = ConvertAxisToOxyPlot(axis.AxisPosition); oxaxis.Title = axis.AxisTitle; oxaxis.Unit = axis.Unit; oxaxis.Key = axis.Key; } } } //"Series" { //delete removed series first. var toRemoveSeries = new List <OxyPlot.Series.LineSeries>(); foreach (OxyPlot.Series.LineSeries oxseries in OxyPlotModel.Series) { { var series = PlotModel.PlotConfiguration.Series.FirstOrDefault(x => x.OxySeries == oxseries);//don't remove xaxis if (series == null) { toRemoveSeries.Add(oxseries); } } } foreach (OxyPlot.Series.LineSeries oxseries in toRemoveSeries) { OxyPlotModel.Series.Remove(oxseries); } foreach (SeriesDefinitionModel series in PlotModel.PlotConfiguration.Series) { //can't use FirstOrDefault as OxyPlot sets default to first axis OxyPlot.Series.LineSeries oxseries = null; foreach (OxyPlot.Series.LineSeries os in OxyPlotModel.Series) { if ((AxisDefinitionModel)os.Tag == series) { oxseries = os; break; } } //var oxseries = OxyPlotModel.Series.FirstOrDefault(x => x.Tag == series) as OxyPlot.Series.LineSeries; if (oxseries == null) { oxseries = new OxyPlot.Series.LineSeries { Title = series.SeriesTitle, Color = OxyColor.FromArgb(series.Color.A, series.Color.R, series.Color.G, series.Color.B), YAxisKey = series.YAxisKey }; oxseries.Tag = series; OxyPlotModel.Series.Add(oxseries); } else { //update oxseries.Title = series.SeriesTitle; oxseries.Color = OxyColor.FromArgb(series.Color.A, series.Color.R, series.Color.G, series.Color.B); oxseries.YAxisKey = series.YAxisKey; } } StringBuilder logFormat = new StringBuilder();//always have time as first parameter AppendLogFormatFromSeries(logFormat, PlotModel.PlotConfiguration.Series); PlotModel.LogFormat = logFormat.ToString(); OnLogFormatChanged(); } OxyPlotModel.InvalidatePlot(true); }
private void CreateScatterPlot() { PlotModel model = new PlotModel(); model.PlotType = PlotType.Cartesian; model.Title = this.tbTitle.Text; double padding = 0.1; LinearAxis xAxis = new LinearAxis(); xAxis.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); xAxis.MajorGridlineStyle = LineStyle.Solid; xAxis.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); xAxis.MinorGridlineStyle = LineStyle.Solid; xAxis.Position = AxisPosition.Bottom; xAxis.MinimumPadding = 0.1; xAxis.MaximumPadding = 0.1; xAxis.Title = tbXAxis.Text; model.Axes.Add(xAxis); LinearAxis yAxis = new LinearAxis(); yAxis.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); yAxis.MajorGridlineStyle = LineStyle.Solid; yAxis.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); yAxis.MinorGridlineStyle = LineStyle.Solid; yAxis.MinimumPadding = 0.1; yAxis.MaximumPadding = 0.1; yAxis.Title = tbYAxis.Text; model.Axes.Add(yAxis); ScatterSeries series = new ScatterSeries(); series.MarkerType = MarkerType.Plus; series.MarkerStroke = OxyColors.Black; float yDataMinimum = float.MaxValue; float yDataMaximum = float.MinValue; float xDataMinimum = float.MaxValue; float xDataMaximum = float.MinValue; foreach (TimedPoint point in points) { PointF p = metadata.CalibrationHelper.GetPointAtTime(point.Point, point.T); series.Points.Add(new ScatterPoint(p.X, p.Y)); yDataMinimum = Math.Min(yDataMinimum, p.Y); yDataMaximum = Math.Max(yDataMaximum, p.Y); xDataMinimum = Math.Min(xDataMinimum, p.X); xDataMaximum = Math.Min(xDataMaximum, p.X); } model.Series.Add(series); if (metadata.CalibrationHelper.CalibratorType == CalibratorType.Plane) { cbCalibrationPlane.Checked = true; cbCalibrationPlane.Enabled = true; CalibrationHelper calibrator = metadata.CalibrationHelper; QuadrilateralF quadImage = calibrator.CalibrationByPlane_GetProjectedQuad(); PointF a = calibrator.GetPointFromRectified(quadImage.A); PointF b = calibrator.GetPointFromRectified(quadImage.B); PointF c = calibrator.GetPointFromRectified(quadImage.C); PointF d = calibrator.GetPointFromRectified(quadImage.D); rectangleAnnotation = new RectangleAnnotation(); rectangleAnnotation.MinimumX = a.X; rectangleAnnotation.MaximumX = b.X; rectangleAnnotation.MinimumY = d.Y; rectangleAnnotation.MaximumY = a.Y; rectangleAnnotation.Fill = OxyColor.FromArgb(96, 173, 223, 247); rectangleAnnotation.Layer = AnnotationLayer.BelowAxes; model.Annotations.Add(rectangleAnnotation); if (a.Y > yDataMaximum || d.Y < yDataMinimum) { yDataMaximum = Math.Max(yDataMaximum, a.Y); yDataMinimum = Math.Min(yDataMinimum, d.Y); double yPadding = (yDataMaximum - yDataMinimum) * padding; yAxis.Maximum = yDataMaximum + yPadding; yAxis.Minimum = yDataMinimum - yPadding; } if (b.X > xDataMaximum || a.X < xDataMinimum) { xDataMaximum = Math.Max(xDataMaximum, b.X); xDataMinimum = Math.Min(xDataMinimum, a.X); double xPadding = (xDataMaximum - xDataMinimum) * padding; xAxis.Maximum = xDataMaximum + xPadding; xAxis.Minimum = xDataMinimum - xPadding; } } else { cbCalibrationPlane.Checked = false; cbCalibrationPlane.Enabled = false; } plotScatter.Model = model; }
/// <summary> /// Converts a <see cref="Color" /> to an <see cref="OxyColor" />. /// </summary> /// <param name="color">The color.</param> /// <returns>An <see cref="OxyColor" />.</returns> public static OxyColor ToOxyColor(this Color color) { return(OxyColor.FromArgb(color.A, color.R, color.G, color.B)); }
/// <summary> /// Initializes a new instance of the <see cref="ChartData" /> class. /// </summary> public ChartData() { this.ChartDataModel = new PlotModel { Title = Labels.ChartWindowChartTitle, LegendPlacement = LegendPlacement.Inside, LegendSymbolLength = 24, LegendBackground = OxyColor.FromArgb(200, 255, 255, 255), LegendBorder = OxyColors.LightGray, SelectionColor = ConverterExtensions.ToOxyColor( Viana.Project.CurrentFilterData.SelectionColor) }; this.DataScatterSeries = new ScatterSeries(); this.DataLineSeries = new LineSeries(); this.InterpolationSeries = new LineSeries(); this.XAxis = new LinearAxis(); this.XAxis.Position = AxisPosition.Bottom; this.XAxis.ExtraGridlines = new double[1]; this.XAxis.ExtraGridlines[0] = 0; this.XAxis.ExtraGridlineThickness = 2; this.XAxis.ExtraGridlineColor = OxyColors.Gray; // this.XAxis.PositionAtZeroCrossing = true; // this.XAxis.TickStyle = TickStyle.Crossing; this.XAxis.MaximumPadding = 0.05; this.XAxis.MinimumPadding = 0.05; this.YAxis = new LinearAxis(); this.YAxis.Position = AxisPosition.Left; this.YAxis.ExtraGridlines = new double[1]; this.YAxis.ExtraGridlines[0] = 0; this.YAxis.ExtraGridlineThickness = 2; this.YAxis.ExtraGridlineColor = OxyColors.Gray; // this.YAxis.PositionAtZeroCrossing = true; // this.YAxis.TickStyle = TickStyle.Crossing; this.YAxis.MaximumPadding = 0.05; this.YAxis.MinimumPadding = 0.05; this.ChartDataModel.Series.Add(this.DataLineSeries); this.ChartDataModel.Series.Add(this.DataScatterSeries); this.ChartDataModel.Series.Add(this.InterpolationSeries); this.ChartDataModel.Series.Add(new FunctionSeries()); this.ChartDataModel.Series.Add(new FunctionSeries()); this.ChartDataModel.Axes.Add(this.XAxis); this.ChartDataModel.Axes.Add(this.YAxis); this.DataScatterSeries.SelectionMode = SelectionMode.Multiple; // Property info of target object this.DataScatterSeries.Mapping = item => new ScatterPoint(GetTargetValue(item, "PositionX"), GetTargetValue(item, "PositionY")); this.DataLineSeries.Mapping = item => new DataPoint(GetTargetValue(item, "PositionX"), GetTargetValue(item, "PositionY")); this.InterpolationSeries.Mapping = item => new DataPoint(((XYSample)item).ValueX, ((XYSample)item).ValueY); this.UpdateModel(); this.UpdateAppearance(); Viana.Project.CurrentFilterData.PropertyChanged += this.CurrentFilterDataPropertyChanged; }
internal static OxyColor ToOxyColor(this Color self) { return(OxyColor.FromArgb(self.A, self.R, self.G, self.B)); }
public override void Calculate(TimeSpan time_frame_span, TimeFrame time_frame) { this.time_frame = time_frame; this.time_frame_span = time_frame_span; for (int i = 0; i < actions_to_calculate.Count; i++) { Action action = new Action(() => { }); bool result = actions_to_calculate.TryDequeue(out action); if (result) { plot_view.Dispatcher.Invoke(action); } } Action action_scroll = () => { if (my_candles == null || my_candles.Count == 0) { return; } var main_area = ((CandleStickArea)all_areas.Find(x => x is CandleStickArea)); var area_series_parallel = new LineSeries() { Color = OxyColor.FromArgb(150, 255, 85, 0), EdgeRenderingMode = EdgeRenderingMode.PreferSharpness }; var items = my_candles.Select(x => new DataPoint(DateTimeAxis.ToDouble(x.TimeStart), (double)x.Close)); line_seria = new LineSeries() { Color = OxyColor.Parse("#FF5500"), MarkerStrokeThickness = 1, StrokeThickness = 1, }; try { line_seria.Points.Clear(); line_seria.Points.AddRange(items); } catch { return; } var X_start = DateTimeAxis.ToDouble(my_candles.First().TimeStart); var X_end = DateTimeAxis.ToDouble(my_candles.Last().TimeStart); date_time_axis_X.Zoom(X_start, X_end); if (plot_model == null) { return; } if (plot_model.Series.ToList().Exists(x => x.SeriesGroupName == "ScrollPoints")) { plot_model.Series.Remove(plot_model.Series.First(x => x.SeriesGroupName == "ScrollPoints")); } try { area_series_parallel.Points.AddRange(items); area_series_parallel.SeriesGroupName = "ScrollPoints"; } catch { return; } plot_model.Series.Add(area_series_parallel); if (plot_model.Annotations.ToList().Exists(x => x.Tag == (object)"screen_viewer_polygon")) { plot_model.Annotations.Remove(plot_model.Annotations.First(x => (object)x.Tag == "screen_viewer_polygon")); } if (!owner.mediator.prime_chart.isFreeze) { double first_candle_X = main_area.plot_model.Axes[0].ActualMinimum; double last_candle_X = main_area.plot_model.Axes[0].ActualMaximum; top_value = plot_model.Axes[1].ActualMaximum; bottom_value = plot_model.Axes[1].ActualMinimum; List <DataPoint> new_points = new List <DataPoint>() { new DataPoint(first_candle_X, top_value), new DataPoint(last_candle_X, top_value), new DataPoint(last_candle_X, bottom_value), new DataPoint(first_candle_X, bottom_value) }; screen_viewer_polygon.Points.Clear(); screen_viewer_polygon.Points.AddRange(new_points); } else { double first_candle_X = main_area.plot_model.Axes[0].ActualMinimum; double last_candle_X = main_area.plot_model.Axes[0].ActualMaximum; top_value = plot_model.Axes[1].ActualMaximum; bottom_value = plot_model.Axes[1].ActualMinimum; List <DataPoint> new_points = new List <DataPoint>() { new DataPoint(screen_viewer_polygon.Points[0].X, top_value), new DataPoint(screen_viewer_polygon.Points[1].X, top_value), new DataPoint(screen_viewer_polygon.Points[2].X, bottom_value), new DataPoint(screen_viewer_polygon.Points[3].X, bottom_value) }; screen_viewer_polygon.Points.Clear(); screen_viewer_polygon.Points.AddRange(new_points); } plot_model.Annotations.Add(screen_viewer_polygon); }; lock (series_locker) { plot_view.Dispatcher.Invoke(action_scroll); } }
private void CalculateResourceChartPlotModel() { lock (m_Lock) { ResourceSeriesSetModel resourceSeriesSet = ResourceSeriesSet; PlotModel plotModel = null; if (resourceSeriesSet != null) { IEnumerable <ResourceSeriesModel> combinedResourceSeries = resourceSeriesSet.Combined.OrderBy(x => x.DisplayOrder); if (combinedResourceSeries.Any()) { plotModel = new PlotModel(); plotModel.Axes.Add(BuildResourceChartXAxis()); plotModel.Axes.Add(BuildResourceChartYAxis()); plotModel.LegendPlacement = LegendPlacement.Outside; plotModel.LegendPosition = LegendPosition.RightMiddle; var total = new List <int>(); m_DateTimeCalculator.UseBusinessDays(UseBusinessDays); foreach (ResourceSeriesModel series in combinedResourceSeries) { if (series != null) { var areaSeries = new AreaSeries { //Smooth = false, StrokeThickness = 0.0, Title = series.Title, Color = OxyColor.FromArgb( series.ColorFormat.A, series.ColorFormat.R, series.ColorFormat.G, series.ColorFormat.B) }; for (int i = 0; i < series.Values.Count; i++) { int j = series.Values[i]; if (i >= total.Count) { total.Add(0); } areaSeries.Points.Add( new DataPoint(ChartHelper.CalculateChartTimeXValue(i, ShowDates, ProjectStart, m_DateTimeCalculator), total[i])); total[i] += j; areaSeries.Points2.Add( new DataPoint(ChartHelper.CalculateChartTimeXValue(i, ShowDates, ProjectStart, m_DateTimeCalculator), total[i])); } plotModel.Series.Add(areaSeries); } } } } ResourceChartPlotModel = plotModel; } RaiseCanExecuteChangedAllCommands(); }
public override void BuildIndicatorSeries(IndicatorSeria indi_seria, List <decimal> data_points, TimeSpan time_frame_span) { var time_step_double = 1 / (1000 * 60 * 60 * 24 / time_frame_span.TotalMilliseconds); indi_seria.DataPoints = data_points; if (indi_seria.DataPoints == null || indi_seria.DataPoints.Count == 0) { return; } if (plot_view == null || plot_model == null) { return; } var main_chart = (CandleStickArea)all_areas.Find(x => x is CandleStickArea); lock (series_locker) { if (main_chart != null && (string)Tag != "Prime") { if (indi_seria.IndicatorType == IndicatorChartPaintType.Column) { if (indi_seria.DataPoints.Count == indi_seria.IndicatorPoints.Count) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorHistogramPoints[indi_seria.IndicatorHistogramPoints.Count - 1] = new DataPoint(items_oxy_candles.Last().X, last_point); } else if (indi_seria.DataPoints.Count == indi_seria.IndicatorPoints.Count + 1) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorHistogramPoints.Add(new DataPoint(items_oxy_candles.Last().X, last_point)); } else { indi_seria.IndicatorHistogramPoints.Clear(); List <DataPoint> points = new List <DataPoint>(); for (int i = 0; i < indi_seria.DataPoints.Count; i++) { double last_point = (double)indi_seria.DataPoints[i]; if (last_point == 0) { last_point = double.NaN; } try { points.Add(new DataPoint(items_oxy_candles[i].X, last_point)); } catch { return; } } indi_seria.IndicatorHistogramPoints = points.ToList(); } LinearBarSeries linear_bar_seria = new LinearBarSeries() { StrokeThickness = 1, StrokeColor = OxyColor.FromArgb(255, 55, 219, 186), FillColor = OxyColor.FromArgb(69, 55, 219, 186), NegativeFillColor = OxyColor.FromArgb(69, 235, 96, 47), NegativeStrokeColor = OxyColor.FromArgb(255, 235, 96, 47), Tag = indi_seria.SeriaName }; linear_bar_seria.Points.AddRange(indi_seria.IndicatorHistogramPoints); if (linear_bar_series_list.Exists(x => (string)x.Tag == indi_seria.SeriaName)) { linear_bar_series_list.Remove(linear_bar_series_list.Find(x => (string)x.Tag == indi_seria.SeriaName)); } linear_bar_series_list.Add(linear_bar_seria); } if (indi_seria.IndicatorType == IndicatorChartPaintType.Line) { if (indi_seria.DataPoints.Count == indi_seria.IndicatorPoints.Count) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorPoints[indi_seria.IndicatorPoints.Count - 1] = new DataPoint(items_oxy_candles.Last().X, last_point); indi_seria.IndicatorPoints[indi_seria.IndicatorPoints.Count - 1] = new DataPoint(items_oxy_candles.Last().X, last_point); } else if (indi_seria.DataPoints.Count == indi_seria.IndicatorPoints.Count + 1) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorPoints.Add(new DataPoint(items_oxy_candles.Last().X, last_point)); } else { indi_seria.IndicatorPoints.Clear(); List <DataPoint> points = new List <DataPoint>(); for (int i = 0; i < indi_seria.DataPoints.Count; i++) { double last_point = (double)indi_seria.DataPoints[i]; if (last_point == 0) { last_point = double.NaN; } try { points.Add(new DataPoint(items_oxy_candles[i].X, last_point)); } catch { return; } } ; indi_seria.IndicatorPoints = points; } LineSeries line_seria = new LineSeries() { StrokeThickness = 1, LineStyle = LineStyle.Solid, Color = indi_seria.OxyColor, Tag = indi_seria.SeriaName }; line_seria.Points.AddRange(indi_seria.IndicatorPoints); if (lines_series_list.Exists(x => (string)x.Tag == indi_seria.SeriaName)) { lines_series_list.Remove(lines_series_list.Find(x => (string)x.Tag == indi_seria.SeriaName)); } lines_series_list.Add(line_seria); } if (indi_seria.IndicatorType == IndicatorChartPaintType.Point) { if (indi_seria.DataPoints.Count == indi_seria.IndicatorScatterPoints.Count) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorScatterPoints[indi_seria.IndicatorScatterPoints.Count - 1] = new ScatterPoint(items_oxy_candles.Last().X, last_point); } else if (indi_seria.DataPoints.Count == indi_seria.IndicatorScatterPoints.Count + 1) { double last_point = (double)indi_seria.DataPoints.Last(); if (last_point == 0) { last_point = double.NaN; } indi_seria.IndicatorScatterPoints.Add(new ScatterPoint(items_oxy_candles.Last().X, last_point)); } else { indi_seria.IndicatorScatterPoints.Clear(); List <ScatterPoint> points = new List <ScatterPoint>(); for (int i = 0; i < indi_seria.DataPoints.Count; i++) { double last_point = (double)indi_seria.DataPoints[i]; if (last_point == 0) { last_point = double.NaN; } try { points.Add(new ScatterPoint(items_oxy_candles[i].X, last_point)); } catch { return; } } ; indi_seria.IndicatorScatterPoints = points; } ScatterSeries scatter_seria = new ScatterSeries() { MarkerType = MarkerType.Circle, MarkerFill = indi_seria.OxyColor, MarkerSize = 2, MarkerStrokeThickness = 0, Tag = indi_seria.SeriaName }; scatter_seria.Points.AddRange(indi_seria.IndicatorScatterPoints); if (scatter_series_list.Exists(x => (string)x.Tag == indi_seria.SeriaName)) { scatter_series_list.Remove(scatter_series_list.Find(x => (string)x.Tag == indi_seria.SeriaName)); } scatter_series_list.Add(scatter_seria); } } } }
/// <summary> /// The color picker selected color changed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The <see cref="System.Windows.RoutedPropertyChangedEventArgs{Color}"/> instance containing the event /// data. /// </param> private void ColorPickerSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs <Color> e) { Color c = this.ColorPicker.SelectedColor; this.SeriesColor = OxyColor.FromArgb(c.A, c.R, c.G, c.B); }
public void Run([JetBrains.Annotations.NotNull] CalculationProfiler cp, [JetBrains.Annotations.NotNull] string outputDirectory, [JetBrains.Annotations.NotNull] string source) { //var cp = CalculationProfiler.Read(@"C:\work\CalculationBenchmarks.ActionCarpetPlotTest\"); InitializeDuration2(cp.MainPart); MergeAndCompress(cp.MainPart); InitPartsList(cp.MainPart); const int fontsize = 6;// = GetFontsize(cp.MainPart); //const string xaxislabel = "Time Consumption in CPUSeconds"; OxyPalette p; if (_parts.Count > 1) { p = OxyPalettes.HueDistinct(_parts.Count); } else { p = OxyPalettes.Hue64; } var plotModel1 = new PlotModel { LegendBorderThickness = 0, LegendOrientation = LegendOrientation.Vertical, LegendPlacement = LegendPlacement.Inside, LegendPosition = LegendPosition.TopLeft, PlotAreaBorderColor = OxyColors.White, LegendFontSize = fontsize, LegendSymbolMargin = 25, DefaultFontSize = fontsize }; var ca = new CategoryAxis { Position = AxisPosition.Left, GapWidth = 0, MaximumPadding = 0.03, MajorTickSize = 0 }; plotModel1.Axes.Add(ca); /* var la = new LinearAxis * { * Minimum = 0, * MinimumPadding = 0, * Title = ChartLocalizer.Get().GetTranslation(xaxislabel), * Position = AxisPosition.Bottom, * MinorTickSize = 0 * };*/ /* plotModel1.Axes.Add(la); * var caSub = new CategoryAxis(); * caSub.StartPosition = 0.5; * caSub.EndPosition = 1; * caSub.Position = AxisPosition.Left; * caSub.Key = "Sub"; * caSub.GapWidth = 0.3; * caSub.MajorTickSize = 0; * caSub.MinorTickSize = 0; * plotModel1.Axes.Add(caSub);*/ //const double runningSum = 0; //var row = 0; // var allBarSeries = new Dictionary<string, IntervalBarSeries>(); //var ba = new BarSeries(); //ba.YAxisKey = "Sub"; //ba.LabelFormatString = "{0:N1} %"; /* foreach (var s in taggingSet.Categories) * { * caSub.Labels.Add(ChartLocalizer.Get().GetTranslation(s)); * var ibs = new IntervalBarSeries(); * // ibs.Title = * var coloridx = taggingSet.GetCategoryIndexOfCategory(s); * ibs.FillColor = p.Colors[coloridx]; * ibs.StrokeThickness = 0; * ibs.FontSize = fontsize; * allBarSeries.Add(s, ibs); * double categorysum = 0; * foreach (var tuple in consumption) * { * if (taggingSet.AffordanceToCategories[tuple.Item1] == s) * { * categorysum += tuple.Item2; * } * } * var percent = categorysum / sum * 100; * var bai = new BarItem(percent); * bai.Color = p.Colors[coloridx]; * ba.Items.Add(bai); * }*/ // plotModel1.Series.Add(ba); var itemsByLevel = new Dictionary <int, IntervalBarSeries>(); _textOffsets.Clear(); AddBars(cp.MainPart, 0, 0, fontsize, itemsByLevel, p, plotModel1); // foreach (IntervalBarSeries series in itemsByLevel.Values) { // plotModel1.Series.Add(series); // } string dstFileName = Path.Combine(outputDirectory, DirectoryNames.CalculateTargetdirectory(TargetDirectory.Charts), "CalculationDurationFlameChart." + source + ".Png"); PngExporter.Export(plotModel1, dstFileName, 3200, 2000, OxyColor.FromArgb(255, 255, 255, 255), 144); //Save(plotModel1, plotName, srcEntry.FullFileName + newFileNameSuffix, basisPath); // ".interval" }
/// <summary> /// Plot calculated distribution with OxyPlot (type 0-null 1-size 2-area 3-combined) /// </summary> /// <param name="categ">categorized information CalBlobAC</param> /// <param name="type">0-null 1-size 2-area 3-combined</param> /// <returns></returns> public static PlotModel ToOxyPlot(this CalPAC categ, int type) { try { var plot = new PlotModel(); switch (type) { case 1: plot.Subtitle = $"Size Distribution\n{categ.Grouping} (N={categ.N})"; break; case 2: plot.Subtitle = $"Area Distribution\n{categ.Grouping} (N={categ.N})"; break; case 3: plot.Subtitle = $"Size & Area-Weighted Size Distribution\n{categ.Grouping} (N={categ.N})"; break; default: plot.Subtitle = ""; break; } plot.Axes.Add(new LinearAxis { Title = "Airspace log10 µm\xB2", Position = AxisPosition.Bottom, Minimum = 0, Maximum = 7, MajorStep = 1, MinorStep = 0.25, TickStyle = TickStyle.Inside }); plot.Axes.Add(new LinearAxis { Title = "Density", Position = AxisPosition.Left, Minimum = 0, Maximum = 1, MajorStep = 0.2, MinorStep = 0.05, TickStyle = TickStyle.Inside }); var fillsize = OxyColor.FromArgb(130, 0, 0, 230); var fillarea = OxyColor.FromArgb(130, 225, 19, 2); var outline = OxyColor.FromArgb(160, 0, 0, 0); var draw1 = OxyColor.FromArgb(255, 79, 154, 6); var draw2 = OxyColor.FromArgb(255, 220, 158, 30); var draw3 = OxyColor.FromArgb(255, 204, 0, 0); double width = 0.05; double offset = 0.05; if (type == 1 || type == 3) // size { var histogram = new RectangleBarSeries() { Title = $"Size Dist (LogLikelihood={categ.gmm1Fit:G2})", FillColor = fillsize, StrokeColor = outline }; for (int i = 0; i < categ.DistCount.Count; i++) { histogram.Items.Add(new RectangleBarItem(categ.DistCount[i][0] - width - offset, 0, categ.DistCount[i][0] + width - offset, categ.DistCount[i][1])); } plot.Series.Add(histogram); plot.Series.Add(FormGaussian($"Population 1 (µ={categ.p1Mean:0.00}, σ={categ.p1Covariance:0.00}, λ={categ.p1Proportion:0.00})", draw1, 0, 10, categ.p1Mean, categ.p1Covariance, categ.p1Proportion)); plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c1_DucDes_CI95_1tail, Text = $"x={categ.c1_DucDes_CI95_1tail:0.0}", Color = fillsize, StrokeThickness = 2 }); } if (type == 2 || type == 3) // area { var histogram = new RectangleBarSeries() { Title = $"Area-Weighted Size Dist (LogLikelihood={categ.gmm2Fit:G2})", FillColor = fillarea, StrokeColor = outline }; for (int i = 0; i < categ.DistArea.Count; i++) { histogram.Items.Add(new RectangleBarItem(categ.DistArea[i][0] - width + offset, 0, categ.DistArea[i][0] + width + offset, categ.DistArea[i][1])); } plot.Series.Add(histogram); plot.Series.Add(FormGaussian($"Population 2 (µ={categ.p2Mean:0.00}, σ={categ.p2Covariance:0.00}, λ={categ.p2Proportion:0.00})", draw2, 0, 10, categ.p2Mean, categ.p2Covariance, categ.p2Proportion)); plot.Series.Add(FormGaussian($"Population 3 (µ={categ.p3Mean:0.00}, σ={categ.p3Covariance:0.00}, λ={categ.p3Proportion:0.00})", draw3, 0, 10, categ.p3Mean, categ.p3Covariance, categ.p3Proportion)); if (type == 3) { plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c2_Sac_Log_Threshold, Text = $"x={categ.c2_Sac_Log_Threshold:0.0}", Color = OxyColor.FromArgb(130, 220, 158, 30), StrokeThickness = 2 }); } plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c2_DucDes_Log_Threshold, Text = $"x={categ.c2_DucDes_Log_Threshold:0.0}", Color = fillarea, StrokeThickness = 2 }); } return(plot); } catch { throw new Exception("Error encountered generating histogram and distribution graph."); } }
private void refresh_plot() { PlotModel pm = plot1.Model; pm.Series.Clear(); pm.Axes.Clear(); var scatterSeries1 = new ScatterSeries { BinSize = 8, MarkerFill = OxyColors.Blue, MarkerSize = 2.0, MarkerStroke = OxyColors.Blue, MarkerStrokeThickness = 1.0, MarkerType = MarkerType.Circle }; var scatterSeries2 = new ScatterSeries { BinSize = 8, MarkerFill = OxyColors.Red, MarkerSize = 2.0, MarkerStroke = OxyColors.Red, MarkerStrokeThickness = 1.0, MarkerType = MarkerType.Circle }; var lineSeries1 = new LineSeries { Color = OxyColors.Blue, LineStyle = LineStyle.Solid, StrokeThickness = 1.0, Smooth = true }; var lineSeries2 = new LineSeries { Color = OxyColors.Red, LineStyle = LineStyle.Solid, StrokeThickness = 1.0, Smooth = true }; if (checkBoxLines.Checked) { lineSeries1.Smooth = false; lineSeries2.Smooth = false; } var stemSeries1 = new StemSeries { Color = OxyColors.Blue, StrokeThickness = 1.0, }; var stemSeries2 = new StemSeries { Color = OxyColors.Red, StrokeThickness = 1.0 }; if (comboBoxPlotType.Text.Contains("xyCount")) { plot_xycounts_vs_time(scatterSeries1, scatterSeries2, stemSeries1, stemSeries2, lineSeries1, lineSeries2); pm.Series.Add(scatterSeries1); pm.Series.Add(scatterSeries2); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); plot_fit(scatterSeries2, lineSeries2); } pm.Series.Add(lineSeries1); pm.Series.Add(lineSeries2); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); pm.Series.Add(stemSeries2); } } else if (comboBoxPlotType.Text.Contains("xCount")) { plot_xcounts_vs_time(scatterSeries1, stemSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); } pm.Series.Add(lineSeries1); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); } } else if (comboBoxPlotType.Text.Contains("yCount")) { plot_ycounts_vs_time(scatterSeries1, stemSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); } pm.Series.Add(lineSeries1); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); } } else if (comboBoxPlotType.Text.Contains("Interval")) { plot_interval_vs_time(scatterSeries1, stemSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); } pm.Series.Add(lineSeries1); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); } } else if (comboBoxPlotType.Text.Contains("xyVelocity")) { plot_xyvelocity_vs_time(scatterSeries1, scatterSeries2, stemSeries1, stemSeries2, lineSeries1, lineSeries2); pm.Series.Add(scatterSeries1); pm.Series.Add(scatterSeries2); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); plot_fit(scatterSeries2, lineSeries2); } pm.Series.Add(lineSeries1); pm.Series.Add(lineSeries2); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); pm.Series.Add(stemSeries2); } } else if (comboBoxPlotType.Text.Contains("xVelocity")) { plot_xvelocity_vs_time(scatterSeries1, stemSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); } pm.Series.Add(lineSeries1); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); } } else if (comboBoxPlotType.Text.Contains("yVelocity")) { plot_yvelocity_vs_time(scatterSeries1, stemSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (!checkBoxLines.Checked) { plot_fit(scatterSeries1, lineSeries1); } pm.Series.Add(lineSeries1); if (checkBoxStem.Checked) { pm.Series.Add(stemSeries1); } } else if (comboBoxPlotType.Text.Contains("X vs. Y")) { plot_x_vs_y(scatterSeries1, lineSeries1); pm.Series.Add(scatterSeries1); if (checkBoxLines.Checked) { pm.Series.Add(lineSeries1); } } var linearAxis1 = new LinearAxis(); linearAxis1.AbsoluteMinimum = x_min - (x_max - x_min) / 20.0; linearAxis1.AbsoluteMaximum = x_max + (x_max - x_min) / 20.0; linearAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis1.MajorGridlineStyle = LineStyle.Solid; linearAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis1.MinorGridlineStyle = LineStyle.Solid; linearAxis1.Position = AxisPosition.Bottom; linearAxis1.Title = xlabel; pm.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); linearAxis2.AbsoluteMinimum = y_min - (y_max - y_min) / 20.0; linearAxis2.AbsoluteMaximum = y_max + (y_max - y_min) / 20.0; linearAxis2.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis2.MajorGridlineStyle = LineStyle.Solid; linearAxis2.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis2.MinorGridlineStyle = LineStyle.Solid; linearAxis2.Title = ylabel; pm.Axes.Add(linearAxis2); plot1.RefreshPlot(true); }
public static OxyColor ConvertColorToOxyColor(Color color) { OxyColor oxyColor = OxyColor.FromArgb(color.A, color.R, color.G, color.B); return(oxyColor); }
private PlotModel CreatePlot(IEnumerable <TimeSeriesPlotData> timeSeriesPlotData, Kinematics component, string abbreviation, string title, TimeModel timeModel) { if (timeSeriesPlotData == null) { return(null); } PlotModel model = new PlotModel(); model.PlotType = PlotType.XY; model.Title = title; LinearAxis xAxis = new LinearAxis(); xAxis.Position = AxisPosition.Bottom; xAxis.MajorGridlineStyle = LineStyle.Solid; xAxis.MinorGridlineStyle = LineStyle.Dot; xAxis.MinimumPadding = 0.02; xAxis.MaximumPadding = 0.05; model.Axes.Add(xAxis); if (timeModel == TimeModel.Absolute || timeModel == TimeModel.Relative) { xAxis.Title = ScreenManagerLang.DataAnalysis_TimeAxisMilliseconds; } else { xAxis.Title = "Time"; } LinearAxis yAxis = new LinearAxis(); yAxis.Position = AxisPosition.Left; yAxis.MajorGridlineStyle = LineStyle.Solid; yAxis.MinorGridlineStyle = LineStyle.Dot; yAxis.MinimumPadding = 0.05; yAxis.MaximumPadding = 0.1; yAxis.Title = string.Format("{0} ({1})", title, abbreviation); model.Axes.Add(yAxis); foreach (TimeSeriesPlotData tspd in timeSeriesPlotData) { LineSeries series = new LineSeries(); series.Title = tspd.Label; series.Color = OxyColor.FromArgb(tspd.Color.A, tspd.Color.R, tspd.Color.G, tspd.Color.B); series.MarkerType = MarkerType.None; series.Smooth = true; double[] points = tspd.TimeSeriesCollection[component]; long[] times = tspd.TimeSeriesCollection.Times; double firstTime = TimestampToMilliseconds(times[0]); double timeSpan = TimestampToMilliseconds(times[times.Length - 1]) - firstTime; for (int i = 0; i < points.Length; i++) { double value = points[i]; if (double.IsNaN(value)) { continue; } double time = TimestampToMilliseconds(times[i]); switch (timeModel) { case TimeModel.Relative: time -= firstTime; break; case TimeModel.Normalized: time = (time - firstTime) / timeSpan; break; case TimeModel.Absolute: default: break; } series.Points.Add(new DataPoint(time, value)); } model.Series.Add(series); } return(model); }
private void btnViewGraph_Click(object sender, EventArgs e) { if (data_g == null) { return; } PlotModel myModel = new PlotModel(); myModel.Series.Add(new FunctionSeries()); LineSeries linePoints = new LineSeries(); LineSeries lineMin = new LineSeries(); LineSeries lineMax = new LineSeries(); LineSeries lineRed = new LineSeries(); LineSeries lineB1 = new LineSeries(); LineSeries lineB2 = new LineSeries(); LineSeries lineV1 = new LineSeries(); DataPoint XYpoint = new DataPoint(); linePoints.Color = lineMin.Color = lineMax.Color = OxyColor.FromArgb(255, 0, 0, 0); lineMin.LineStyle = LineStyle.Dot; lineMax.LineStyle = LineStyle.Dot; lineMin.StrokeThickness = 1; lineMax.StrokeThickness = 1; lineRed.Color = OxyColor.FromArgb(255, 255, 0, 0); lineRed.StrokeThickness = 1; lineB1.StrokeThickness = 1; lineB2.StrokeThickness = 1; lineB1.Color = lineB2.Color = OxyColor.FromArgb(255, 0, 0, 255); lineB1.LineStyle = LineStyle.Dot; lineB2.LineStyle = LineStyle.Dot; lineV1.Color = OxyColor.FromArgb(255, 0, 255, 0); lineV1.LineStyle = LineStyle.Dot; lineV1.StrokeThickness = 1; var listMax = new List <double>(); foreach (var g in data_g) { listMax.Add(g.Max); XYpoint = new DataPoint(g.Frequency, g.Average); linePoints.Points.Add(XYpoint); XYpoint = new DataPoint(g.Frequency, g.Min); lineMin.Points.Add(XYpoint); XYpoint = new DataPoint(g.Frequency, g.Max); lineMax.Points.Add(XYpoint); } double vmax = listMax.Max() + 1; lineRed.Points.Add(new DataPoint(f0, vmax)); lineRed.Points.Add(new DataPoint(f0, 0)); lineB1.Points.Add(new DataPoint(f0a, vmax)); lineB1.Points.Add(new DataPoint(f0a, 0)); lineB2.Points.Add(new DataPoint(f0b, vmax)); lineB2.Points.Add(new DataPoint(f0b, 0)); lineV1.Points.Add(new DataPoint(f0 / 4, vmax)); lineV1.Points.Add(new DataPoint(f0 / 4, 0)); myModel.Series.Add(linePoints); myModel.Series.Add(lineMin); myModel.Series.Add(lineMax); myModel.Series.Add(lineRed); myModel.Series.Add(lineB1); myModel.Series.Add(lineB2); myModel.Series.Add(lineV1); LinearAxis a = new LinearAxis(); LogarithmicAxis b = new LogarithmicAxis(); a.Title = "Amplitude HV"; a.Position = AxisPosition.Left; a.FontSize = 8; a.TitleFontSize = 9; b.Title = "Frequency [Hz]"; b.Position = AxisPosition.Bottom; b.FontSize = 8; b.TitleFontSize = 9; myModel.Axes.Add(a); myModel.Axes.Add(b); PlotForm graph = new PlotForm(myModel); graph.ShowDialog(this); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var color = (Color)value; return(OxyColor.FromArgb(color.A, color.R, color.G, color.B)); }
private void LoadChartData(WhlSKU Sku) { if (Sku != null) { PlotModel PlotArea = new PlotModel(); var endDate = DateTime.Now.ToOADate(); var startDate = DateTime.Now.AddMonths(-6).ToOADate(); var bottomAxis = new DateTimeAxis { Position = AxisPosition.Bottom, Maximum = Convert.ToDouble(endDate), AbsoluteMaximum = Convert.ToDouble(endDate), Title = "Date", StringFormat = "dd/M", MinorIntervalType = DateTimeIntervalType.Days }; var leftAxis = new LinearAxis { Position = AxisPosition.Left, Minimum = 0, AbsoluteMinimum = 0, Title = "Sales" }; var rightAxis = new OxyPlot.Axes.LinearAxis(); rightAxis.Position = AxisPosition.Right; rightAxis.Minimum = 0; rightAxis.AbsoluteMinimum = 0; rightAxis.Maximum = 5000; rightAxis.Title = "Stock"; var query = @"SELECT a.shortSku, a.stockDate, a.Stocklevel, a.StockMinimum, b.maintotal FROM whldata.stock_history as a LEFT JOIN(SELECT /*top (999999999999)*/ a.orderdate, a.shortsku, sum(a.total)as ""maintotal"" FROM (SELECT /*top (999999999999)*/ orderdate, sku, SUBSTRING(sku, 0, 8) as ""shortsku"", sum(salequantity) as ""sales"", CAST(SUBSTRING(sku, 8, 4) as unsigned int) as ""packsize"", sum(salequantity * CAST(SUBSTRING(sku, 8, 4) as unsigned int)) as 'total' FROM whldata.newsales_raw WHERE sku LIKE '" + Sku.ShortSku + @"%' group by sku, orderDate order by orderdate) as a GROUP BY orderdate, shortsku ORDER BY orderDate) as b on b.shortsku = SUBSTRING(a.shortSku, 0, 8) AND b.orderDate = a.stockDate WHERE a.shortsku = '" + Sku.SKU + @"' ORDER BY StockDate ASC"; var queryDict = MySQL.SelectData(query) as ArrayList; var stockHistoryPoints = new List <DataPoint>(); var salesHistoryPoints = new List <DataPoint>(); var stockHistoryPoints2 = new List <DataPoint>(); var salesHistoryPoints2 = new List <DataPoint>(); var salesSeries = new LineSeries(); var stockSeries = new LineSeries(); OxyPlot.Series.AreaSeries StockAreaSeries = new OxyPlot.Series.AreaSeries(); OxyPlot.Series.AreaSeries SalesAreaSeries = new OxyPlot.Series.AreaSeries(); var MaxStock = 0; var MaxSales = 0; try { bottomAxis.AbsoluteMinimum = Convert.ToDouble(DateTime.Parse((queryDict[0] as ArrayList)[1].ToString()).ToOADate()); var arrayList = queryDict[0] as ArrayList; if (arrayList != null) { bottomAxis.Minimum = Convert.ToDouble( DateTime.Parse(arrayList[1].ToString()).ToOADate()); } } catch (Exception) { bottomAxis.AbsoluteMinimum = Convert.ToDouble(startDate); bottomAxis.Minimum = Convert.ToDouble(startDate); } foreach (ArrayList result in queryDict) { double StockTotal; if (ignoreStockMinimums) { StockTotal = Convert.ToDouble(Int32.Parse(result[2].ToString())); } else { StockTotal = Convert.ToDouble( Int32.Parse(result[2].ToString()) + Int32.Parse(result[3].ToString())); } Double SalesTotal; try { if (MaxStock < Int32.Parse(result[2].ToString()) + Int32.Parse(result[3].ToString())) { MaxStock = Int32.Parse(result[2].ToString()) + Int32.Parse(result[3].ToString()); } if (DBNull.Value != result[4]) { if (MaxSales < Int32.Parse(result[4].ToString())) { MaxSales = Int32.Parse(result[4].ToString()); } } } catch (Exception) { } try { SalesTotal = Convert.ToDouble(Int32.Parse(result[4].ToString())); } catch (Exception) { Console.WriteLine(); SalesTotal = Convert.ToDouble(0); } var Date = Convert.ToDouble(DateTime.Parse(result[1].ToString()).ToOADate()); var StockHistoryPoint = new DataPoint(Date, StockTotal); var SaleHistoryPoint = new DataPoint(Date, SalesTotal); var StockHistoryPoint2 = new DataPoint(Date, 0); salesHistoryPoints.Add(SaleHistoryPoint); stockHistoryPoints.Add(StockHistoryPoint); salesHistoryPoints2.Add(StockHistoryPoint2); stockHistoryPoints2.Add(StockHistoryPoint2); } salesSeries.Points.AddRange(salesHistoryPoints); stockSeries.Points.AddRange(stockHistoryPoints); rightAxis.Key = "StockKey"; salesSeries.YAxisKey = leftAxis.Key; salesSeries.CanTrackerInterpolatePoints = false; salesSeries.Color = OxyColor.FromRgb(237, 125, 49); salesSeries.Title = "Sales History"; stockSeries.YAxisKey = rightAxis.Key; stockSeries.CanTrackerInterpolatePoints = false; if (this.useAreaForChart) { StockAreaSeries.Points.AddRange(stockHistoryPoints); StockAreaSeries.YAxisKey = rightAxis.Key; StockAreaSeries.CanTrackerInterpolatePoints = false; StockAreaSeries.Fill = OxyColor.FromRgb(176, 195, 230); StockAreaSeries.Color = OxyColor.FromRgb(138, 167, 218); StockAreaSeries.Color2 = OxyColor.FromRgb(138, 167, 218); StockAreaSeries.Points2.AddRange(stockHistoryPoints2); //StockAreaSeries.ConstantY2 = 0; StockAreaSeries.Title = "Stock History Area"; SalesAreaSeries.Points.AddRange(salesHistoryPoints); SalesAreaSeries.CanTrackerInterpolatePoints = false; SalesAreaSeries.Fill = OxyColor.FromArgb(140, 237, 125, 49); SalesAreaSeries.Color = OxyColor.FromArgb(255, 138, 167, 218); SalesAreaSeries.Color2 = OxyColor.FromRgb(138, 167, 218); SalesAreaSeries.Points2.AddRange(stockHistoryPoints2); //StockAreaSeries.ConstantY2 = 0; SalesAreaSeries.Title = "Sales History Area"; PlotArea.Series.Add(StockAreaSeries); PlotArea.Series.Add(SalesAreaSeries); } else { stockSeries.Color = OxyColors.DarkGreen; stockSeries.Title = "Stock History"; PlotArea.Series.Add(stockSeries); PlotArea.Series.Add(salesSeries); } if (MaxSales == 0) { leftAxis.AbsoluteMaximum = 1; rightAxis.AbsoluteMaximum += 10; leftAxis.Title = "No sales"; } if (MaxSales > 0) { leftAxis.AbsoluteMaximum = MaxSales * 1.15; leftAxis.Maximum = MaxSales * 1.1; rightAxis.Maximum = MaxStock * 1.1; rightAxis.AbsoluteMaximum = MaxStock * 1.15; } leftAxis.IsZoomEnabled = false; leftAxis.AbsoluteMaximum = MaxSales; rightAxis.AbsoluteMaximum = MaxStock; PlotArea.Axes.Add(bottomAxis); PlotArea.Axes.Add(leftAxis); PlotArea.Axes.Add(rightAxis); PlotArea.Title = Sku.ShortSku + " Sales/Stock History"; this.plotGlobal = PlotArea; } }
/// <summary> /// Initializes a new instance of the <see cref="MainViewModel" /> class. /// </summary> public MainViewModel() { // Create the plot model var model = new PlotModel { Title = "Pump RPM by Temperature" }; model.IsLegendVisible = false; // Create two line series (markers are hidden by default) var s1 = new LineSeries { Title = "Series 1", MarkerType = MarkerType.Circle, MarkerFill = OxyColor.FromArgb(0, 15, 35, 100), MarkerStroke = OxyColor.FromArgb(255, 15, 35, 100), MarkerStrokeThickness = 2, MarkerSize = 4, Color = OxyColor.FromArgb(255, 15, 35, 100) }; s1.Points.Add(new DataPoint(00, 00)); s1.Points.Add(new DataPoint(10, 10)); s1.Points.Add(new DataPoint(20, 20)); s1.Points.Add(new DataPoint(30, 30)); s1.Points.Add(new DataPoint(40, 40)); s1.Points.Add(new DataPoint(50, 50)); s1.Points.Add(new DataPoint(60, 60)); s1.Points.Add(new DataPoint(70, 70)); s1.Points.Add(new DataPoint(80, 80)); s1.Points.Add(new DataPoint(90, 90)); s1.Points.Add(new DataPoint(100, 100)); // Add the series to the plot model model.Series.Add(s1); int indexOfPointToMove = -1; // Subscribe to the mouse down event on the line series s1.MouseDown += (s, e) => { if (e.HitTestResult == null) { return; } if (e.ChangedButton == OxyMouseButton.Right) { int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index); var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]); if ((nearestPoint - e.Position).Length < 10) { s1.Points.RemoveAt(indexOfNearestPoint); } indexOfPointToMove = -1; model.InvalidatePlot(false); e.Handled = true; } // only handle the left mouse button (right button can still be used to pan) if (e.ChangedButton == OxyMouseButton.Left) { int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index); var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]); // Check if we are near a point if ((nearestPoint - e.Position).Length < 10) { // Start editing this point indexOfPointToMove = indexOfNearestPoint; } else if (s1.Points.Count <= 64) { // otherwise create a point on the current line segment int i = (int)e.HitTestResult.Index + 1; s1.Points.Insert(i, s1.InverseTransform(e.Position)); s1.Points.Sort((a, b) => a.X.CompareTo(b.X)); indexOfPointToMove = i; } // Change the linestyle while editing s1.LineStyle = LineStyle.DashDot; // Remember to refresh/invalidate of the plot model.InvalidatePlot(false); // Set the event arguments to handled - no other handlers will be called. e.Handled = true; } }; s1.MouseMove += (s, e) => { if (indexOfPointToMove >= 0) { // Move the point being edited. s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position); model.InvalidatePlot(false); e.Handled = true; } }; s1.MouseUp += (s, e) => { // Stop editing if (indexOfPointToMove >= 0) { var pt = s1.Points[indexOfPointToMove]; var x = Math.Round(pt.X); var y = Math.Round(pt.Y); s1.Points[indexOfPointToMove] = new DataPoint(x, y); } s1.Points.Sort((a, b) => a.X.CompareTo(b.X)); indexOfPointToMove = -1; s1.LineStyle = LineStyle.Solid; model.InvalidatePlot(false); e.Handled = true; }; model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { // Add a point to the line series. s1.Points.Add(s1.InverseTransform(e.Position)); s1.Points.Sort((a, b) => a.X.CompareTo(b.X)); indexOfPointToMove = s1.Points.Count - 1; model.InvalidatePlot(false); e.Handled = true; } }; // Axes are created automatically if they are not defined // Set the Model property, the INotifyPropertyChanged event will make the WPF Plot control update its content this.Model = model; }
public static PlotModel BindingItemsSource() { var items = new Collection <Item> { new Item { Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19 }, new Item { Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9 }, new Item { Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29 } }; var plotModel1 = new PlotModel { Title = "Binding to ItemsSource" }; var l = new Legend { LegendPlacement = LegendPlacement.Outside }; plotModel1.Legends.Add(l); var categoryAxis1 = new CategoryAxis { Position = AxisPosition.Left, LabelField = "Label", ItemsSource = items, MajorStep = 1, MinorStep = 1 }; plotModel1.Axes.Add(categoryAxis1); var linearAxis1 = new LinearAxis { Position = AxisPosition.Bottom, AbsoluteMinimum = 0, MinimumPadding = 0 }; plotModel1.Axes.Add(linearAxis1); var series1 = new BarSeries { FillColor = OxyColor.FromArgb(255, 78, 154, 6), ValueField = "Value1", Title = "2009", ItemsSource = items }; plotModel1.Series.Add(series1); var series2 = new BarSeries { FillColor = OxyColor.FromArgb(255, 200, 141, 0), ValueField = "Value2", Title = "2010", ItemsSource = items }; plotModel1.Series.Add(series2); var series3 = new BarSeries { FillColor = OxyColor.FromArgb(255, 204, 0, 0), ValueField = "Value3", Title = "2011", ItemsSource = items }; plotModel1.Series.Add(series3); return(plotModel1); }
PlotModel GetHistogram(SubCategoryStat stats) { PlotModel model = new PlotModel(); CategoryAxis categoryAxis; LinearAxis valueAxis; int maxCount; valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0, MinorStep = 1, MajorStep = 1, Minimum = 0 }; categoryAxis = new CategoryAxis() { ItemsSource = stats.OptionStats, LabelField = "Name", Angle = 20.0 }; model.Series.Add(new ColumnSeries { Title = Catalog.GetString("Total"), ItemsSource = stats.OptionStats, ValueField = "TotalCount" }); if (ShowTeams) { model.Series.Add(new ColumnSeries { Title = HomeName, ItemsSource = stats.OptionStats, ValueField = "LocalTeamCount", FillColor = OxyColor.FromArgb(0xFF, 0xFF, 0x33, 0x0), }); model.Series.Add(new ColumnSeries { Title = AwayName, ItemsSource = stats.OptionStats, ValueField = "VisitorTeamCount", FillColor = OxyColor.FromArgb(0xFF, 0, 0x99, 0xFF) }); } model.Axes.Add(categoryAxis); model.Axes.Add(valueAxis); if (stats.OptionStats.Count != 0) { maxCount = stats.OptionStats.Max(o => o.TotalCount); if (maxCount > 10 && maxCount <= 50) { valueAxis.MinorStep = 5; valueAxis.MajorStep = 10; } else if (maxCount > 50 && maxCount <= 100) { valueAxis.MinorStep = 10; valueAxis.MajorStep = 20; } else if (maxCount > 100) { valueAxis.MinorStep = 10; valueAxis.MajorStep = 50; } } OxyColor text_color = OxyColor.FromArgb(LongoMatch.App.Current.Style.PaletteText.A, LongoMatch.App.Current.Style.PaletteText.R, LongoMatch.App.Current.Style.PaletteText.G, LongoMatch.App.Current.Style.PaletteText.B); model.TextColor = text_color; model.TitleColor = text_color; model.SubtitleColor = text_color; return(model); }
public void UpdateChart() { if (Thread.CurrentThread != Dispatcher.Thread) { Dispatcher.BeginInvoke(new Action(UpdateChart)); return; } //--- remove all series PlotViewModel.Series.Clear(); while (Drawer.Candles.MoveNext()) { this.Candles.Items.Add(new ChartBar(Drawer.Candles.Current)); this.Volumes.Items.Add(new ChartBarVol(Drawer.Candles.Current) { }); } //create exes CreateAxes(); //--- if (Candles.Items.Count > 0) { PlotViewModel.Series.Add(Candles); PlotViewModel.Series.Add(Volumes); //draw volumes //PlotViewModel.Series.Add(Volumes); } //----------------- HORIZONTAL LINES -------------- var levels = new List <double>(Drawer.HorizontalLines); levels.Sort(); for (int l = 1; l < levels.Count; l++) { if (levels[l] - levels[l - 1] < 0.00001) { levels[l] = levels[l - 1] + 0.00001; } } foreach (var level in levels) { //if (level < range.High + range.Length && level > range.Low - range.Length) { LineSeriesEx line = new LineSeriesEx(false) { MarkerStrokeThickness = 1, LineStyle = LineStyle.Solid, Color = OxyColor.FromArgb(200, 1, 1, 200), StrokeThickness = 0.5f, }; line.Points.Add(new DataPoint(0, level)); line.Points.Add(new DataPoint(PlotViewModel.Axes[0].Maximum - 1, level)); PlotViewModel.Series.Add(line); } } //----------------- lines ---------------------- this.Lines.Clear(); foreach (var line in Drawer.Lines.Concat(Drawer.VerticalLines)) { var ingnoreZoom = Drawer.VerticalLines.Contains(line); LineSeriesEx lineserie = new LineSeriesEx(ingnoreZoom) { MarkerStrokeThickness = 2, LineStyle = LineStyle.Solid, Color = OxyColor.FromArgb(line.Color.A, line.Color.R, line.Color.G, line.Color.B), StrokeThickness = 3f, YAxisKey = line.AxisId ?? this.Candles_Yaxis.Key }; lineserie.Points.AddRange( line.Points.Select(dot => new DataPoint(dot.X.ToAxisDouble(), dot.Y))); PlotViewModel.Series.Add(lineserie); this.Lines.Add(lineserie); } //-------plot points --------------- var pointsSerie = new OxyPlot.Series.ScatterSeries() { MarkerSize = 15, MarkerType = MarkerType.Circle }; for (int p = 0; p < Drawer.Points.Count; p++) { pointsSerie.Points.Add( new ScatterPoint(Drawer.Points[p].Time.ToAxisDouble(), Drawer.Points[p].Value, 5)); } PlotViewModel.Series.Add(pointsSerie); //---------- ADJUST X to show 100 candles PlotViewModel.Axes[0].Minimum = Drawer.InitialView.start.ToAxisDouble(); PlotViewModel.Axes[0].Maximum = Drawer.InitialView.end.ToAxisDouble(); PlotViewModel.Axes[0].Reset(); //--------- ADJUST Y AdjustYAxisZoom(); PlotViewModel.InvalidatePlot(true); return; }
public async Task Refresh(List <Guid> oilsGuids, DateTime fromDate, DateTime toDate) { await Dispatcher.BeginInvoke(new Action(() => _BUSY_INDICATOR.IsBusy = true)); List <Oil> oils; if (_isFistHit) { fromDate = DateTime.Today.AddMonths(-11); toDate = DateTime.Today; oils = (await App.Store.Oils.GetOils()).Take(4).ToList(); _isFistHit = false; } else { if (_stopwatch.ElapsedMilliseconds < 10000) { return; } oils = App.Store.Oils.GetOils(oilsGuids); } var plotModel = new PlotModel { Title = "Ventes Mensuel des Huiles en bidons", TitleColor = OxyColors.Gray, TitleFontSize = 15, TitleFontWeight = FontWeights.Normal, LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.BottomCenter, LegendOrientation = LegendOrientation.Horizontal, LegendBorderThickness = 0 }; foreach (var oil in oils) { var col = RandomHelper.RandomColor(); plotModel.Series.Add(new ColumnSeries { ItemsSource = (await App.Store.Oils.GetMonthlySales(new List <Guid> { oil.OilGuid }, fromDate, toDate)), ValueField = "Value", Title = oil.Libel.ToUpper(), FillColor = OxyColor.FromArgb(col.A, col.R, col.G, col.B), LabelPlacement = LabelPlacement.Outside, LabelFormatString = "{0:f0}", TextColor = OxyColors.DimGray, StrokeColor = OxyColors.White, StrokeThickness = 1, ColumnWidth = 5 }); } var axis = DateTimeHelper.EachMonth( new DateTime(fromDate.Year, fromDate.Month, 1), new DateTime(toDate.Year, toDate.Month, 1)) .Select(month => new KeyValuePair <string, double>(month.ToString("MMM-yy"), 0)).ToList(); plotModel.Axes.Add(new CategoryAxis { ItemsSource = axis, LabelField = "Key", AxislineStyle = LineStyle.Solid, AxislineThickness = 0.1, GapWidth = 0.15, Position = AxisPosition.Bottom, TickStyle = TickStyle.Outside, AxislineColor = OxyColors.Transparent, IsZoomEnabled = false }); plotModel.Axes.Add(new LinearAxis { MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, AxislineStyle = LineStyle.Automatic, AxislineThickness = 0.1, TickStyle = TickStyle.Outside, AxislineColor = OxyColors.Transparent, IsZoomEnabled = false }); await Dispatcher.BeginInvoke(new Action(() => { _PLOT_VIEW.Model = plotModel; _BUSY_INDICATOR.IsBusy = false; })); }
public static PlotModel Create(ModelType type) { PlotModel model = null; switch (type) { case ModelType.SineWave: model = CreateSineModel(0.002); break; case ModelType.SmoothInterpolation: model = CreateSineModel(1); model.Title = "Smooth interpolation"; // Add markers to this plot var ls = model.Series[0] as LineSeries; if (ls == null) { return(null); } ls.MarkerType = MarkerType.Circle; ls.Color = OxyColor.FromArgb(0xFF, 154, 6, 78); ls.MarkerStroke = ls.Color; ls.MarkerFill = OxyColor.FromAColor(0x70, ls.Color); ls.MarkerStrokeThickness = 2; ls.MarkerSize = 4; var ls2 = CreateLineSeries(Math.Sin, 0, 10, 1, "interpolated curve"); ls2.Smooth = true; model.Series.Add(ls2); break; case ModelType.NormalDistribution: model = CreateNormalDistributionModel(); break; case ModelType.SquareWave: model = CreateSquareWave(); break; case ModelType.LogLog: model = CreateLogLogPlot(); break; case ModelType.LogLin: model = CreateLogLinPlot(); break; case ModelType.LinLog: model = CreateLinLogPlot(); break; case ModelType.Clover: // http://people.reed.edu/~jerry/Clover/cloverexcerpt.pdf // http://www-math.bgsu.edu/z/calc3/vectorvalued1.html model = CreateParametricPlot( t => 2 * Math.Cos(2 * t) * Math.Cos(t), t => 2 * Math.Cos(2 * t) * Math.Sin(t), // t=>-4*Math.Sin(2*t)*Math.Cos(t)-2*Math.Cos(2*t)*Math.Sin(t), // t=>-4*Math.Sin(2*t)*Math.Sin(t)+2*Math.Cos(2*t)*Math.Cos(t),)))) 0, Math.PI * 2, 0.01, "Parametric function", "Using the CartesianAxes property", "2cos(2t)cos(t) , 2cos(2t)sin(t)"); break; case ModelType.KochSnowflake: model = CreateKochSnowflake(8); break; case ModelType.KochSnowflake2: model = CreateKochSnowflake(8, true); break; case ModelType.KochCurve: model = CreateKochCurve(4); break; case ModelType.ZigZag: model = CreateZigZagCurve(2000); break; case ModelType.MathNotation: model = CreateMathNotationPlot(); break; case ModelType.StraightLine: model = CreateParametricPlot( t => t, t => 1 + t * 1e-8, 0, 10, 0.1, "Straight line", null, null); model.PlotType = PlotType.XY; break; } return(model); }
private void AddLastTenLatLongWithTimeScatterSeries(PlotModel newPlot) { ScatterSeries pointsSeries; OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last Ten Books With Time"); LineSeries overallSeries; OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Overall", 0); OxyColor faintColorBlue = OxyColor.FromArgb(80, OxyColors.Blue.R, OxyColors.Blue.G, OxyColors.Blue.B); overallSeries.Color = faintColorBlue; overallSeries.StrokeThickness = 2; LineSeries lastTenSeries; OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last 10", 0); OxyColor faintColorRed = OxyColor.FromArgb(80, OxyColors.Red.R, OxyColors.Red.G, OxyColors.Red.B); lastTenSeries.Color = faintColorRed; lastTenSeries.StrokeThickness = 2; foreach (var delta in BooksReadProvider.BookLocationDeltas) { int pointSize = 5; PolygonPoint latLong = new PolygonPoint { Latitude = delta.AverageLatitudeLastTen, Longitude = delta.AverageLongitudeLastTen }; double x, y; latLong.GetCoordinates(out x, out y); lastTenSeries.Points.Add(new DataPoint(x, y)); ScatterPoint point = new ScatterPoint(x, y, pointSize, delta.DaysSinceStart) { Tag = delta.Date.ToString("ddd d MMM yyy") }; pointsSeries.Points.Add(point); latLong = new PolygonPoint { Latitude = delta.AverageLatitude, Longitude = delta.AverageLongitude }; latLong.GetCoordinates(out x, out y); overallSeries.Points.Add(new DataPoint(x, y)); } // don't draw these as renders the pic unusable pointsSeries.RenderInLegend = false; pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} )"; newPlot.Series.Add(pointsSeries); List <OxyColor> colors = new List <OxyColor>(); foreach (OxyColor color in OxyPalettes.Jet(200).Colors) { OxyColor faintColor = OxyColor.FromArgb(80, color.R, color.G, color.B); colors.Add(faintColor); } OxyPalette faintPalette = new OxyPalette(colors); newPlot.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = faintPalette, Title = "Days Since Start" }); }
private void sel_Color(object sender, RoutedEventArgs e) { ColorDialog colorDialog = new ColorDialog(); var btn = sender as Button; if (btn == this.A_btn) { colorDialog.SelectedColor = Color.FromArgb(A_color.A, A_color.R, A_color.G, A_color.B); } else if (btn == this.B_btn) { colorDialog.SelectedColor = Color.FromArgb(B_color.A, B_color.R, B_color.G, B_color.B); } else if (btn == this.C_btn) { colorDialog.SelectedColor = Color.FromArgb(C_color.A, C_color.R, C_color.G, C_color.B); } else if (btn == this.X_btn) { colorDialog.SelectedColor = Color.FromArgb(X_color.A, X_color.R, X_color.G, X_color.B); } else if (btn == this.Y_btn) { colorDialog.SelectedColor = Color.FromArgb(Y_color.A, Y_color.R, Y_color.G, Y_color.B); } else if (btn == this.Z_btn) { colorDialog.SelectedColor = Color.FromArgb(Z_color.A, Z_color.R, Z_color.G, Z_color.B); } else if (btn == this.M_btn) { colorDialog.SelectedColor = Color.FromArgb(M_color.A, M_color.R, M_color.G, M_color.B); } else if (btn == this.I_btn) { colorDialog.SelectedColor = Color.FromArgb(I_color.A, I_color.R, I_color.G, I_color.B); } else if (btn == this.O_btn) { colorDialog.SelectedColor = Color.FromArgb(O_color.A, O_color.R, O_color.G, O_color.B); } colorDialog.Owner = this; if ((bool)colorDialog.ShowDialog()) { Color selected_color = colorDialog.SelectedColor; if (btn == this.A_btn) { A_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.A_btn.Background = new SolidColorBrush(Color.FromArgb(this.A_color.A, this.A_color.R, this.A_color.G, this.A_color.B)); } else if (btn == this.B_btn) { B_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.B_btn.Background = new SolidColorBrush(Color.FromArgb(this.B_color.A, this.B_color.R, this.B_color.G, this.B_color.B)); } else if (btn == this.C_btn) { C_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.C_btn.Background = new SolidColorBrush(Color.FromArgb(this.C_color.A, this.C_color.R, this.C_color.G, this.C_color.B)); } else if (btn == this.X_btn) { X_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.X_btn.Background = new SolidColorBrush(Color.FromArgb(this.X_color.A, this.X_color.R, this.X_color.G, this.X_color.B)); } else if (btn == this.Y_btn) { Y_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.Y_btn.Background = new SolidColorBrush(Color.FromArgb(this.Y_color.A, this.Y_color.R, this.Y_color.G, this.Y_color.B)); } else if (btn == this.Z_btn) { Z_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.Z_btn.Background = new SolidColorBrush(Color.FromArgb(this.Z_color.A, this.Z_color.R, this.Z_color.G, this.Z_color.B)); } else if (btn == this.M_btn) { M_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.M_btn.Background = new SolidColorBrush(Color.FromArgb(this.M_color.A, this.M_color.R, this.M_color.G, this.M_color.B)); } else if (btn == this.I_btn) { I_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.I_btn.Background = new SolidColorBrush(Color.FromArgb(this.I_color.A, this.I_color.R, this.I_color.G, this.I_color.B)); } else if (btn == this.O_btn) { O_color = OxyColor.FromArgb(selected_color.A, selected_color.R, selected_color.G, selected_color.B); this.O_btn.Background = new SolidColorBrush(Color.FromArgb(this.O_color.A, this.O_color.R, this.O_color.G, this.O_color.B)); } } }
private void refresh_plot() { PlotModel pm = plot1.Model; pm.Series.Clear(); pm.Axes.Clear(); ResetPlotComponents(); if (checkBoxLines.Checked) { BlueComponent.lines.Smooth = false; RedComponent.lines.Smooth = false; if (dual) { GreenComponent.lines.Smooth = false; YellowComponent.lines.Smooth = false; } } GraphType type = comboBoxPlotType.SelectedItem as GraphType; if (type == null) { MessageBox.Show("Something bad happened! SelectedItem is null..."); return; } else { reset_minmax(); type.PlotFunc(mlog, 0.0, BlueComponent, RedComponent); if (type.DualGraph == GraphType.GT.nolines) { BlueComponent.Add(pm, checkBoxLines.Checked); } else { BlueComponent.Add(pm, checkBoxLines.Checked, checkBoxStem.Checked); if (type.DualGraph == GraphType.GT.dual) { RedComponent.Add(pm, checkBoxLines.Checked, checkBoxStem.Checked); } } if (dual) { type.PlotFunc(mlog2, -(double)numericUpDownDelay.Value, GreenComponent, YellowComponent); if (type.DualGraph == GraphType.GT.nolines) { GreenComponent.Add(pm, checkBoxLines.Checked); } else { GreenComponent.Add(pm, checkBoxLines.Checked, checkBoxStem.Checked); if (type.DualGraph == GraphType.GT.dual) { YellowComponent.Add(pm, checkBoxLines.Checked, checkBoxStem.Checked); } } } } var linearAxis1 = new LinearAxis(); linearAxis1.AbsoluteMinimum = x_min - (x_max - x_min) / 20.0; linearAxis1.AbsoluteMaximum = x_max + (x_max - x_min) / 20.0; linearAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis1.MajorGridlineStyle = LineStyle.Solid; linearAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis1.MinorGridlineStyle = LineStyle.Solid; linearAxis1.Position = AxisPosition.Bottom; linearAxis1.Title = type.AxisX; pm.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); linearAxis2.AbsoluteMinimum = y_min - (y_max - y_min) / 20.0; linearAxis2.AbsoluteMaximum = y_max + (y_max - y_min) / 20.0; linearAxis2.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis2.MajorGridlineStyle = LineStyle.Solid; linearAxis2.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis2.MinorGridlineStyle = LineStyle.Solid; linearAxis2.Title = type.AxisY; pm.Axes.Add(linearAxis2); plot1.RefreshPlot(true); }
public void OnDataChanged() { if (DrawCost && DrawDistance) { throw new Exception("Only one of the values can be drawn at once, 'cost' or 'distance'."); } double[][] matrixValues = null; if (DrawCost) { matrixValues = Dtw.GetCostMatrix(); } if (DrawDistance) { matrixValues = Dtw.GetDistanceMatrix(); } var dtwPath = Dtw.GetPath(); var xLength = Dtw.XLength; var yLength = Dtw.YLength; var cost = Dtw.GetCost(); var costNormalized = Dtw.GetCost() / Math.Sqrt(xLength * xLength + yLength * yLength); var plotModel = new PlotModel(String.Format("Dtw norm by length: {0:0.00}, total: {1:0.00}", costNormalized, cost)) { LegendTextColor = DrawCost || DrawDistance ? OxyColors.White : OxyColors.Black, }; if (matrixValues != null) { var maxMatrixValue = 0.0; for (int i = 0; i < xLength; i++) { for (int j = 0; j < yLength; j++) { maxMatrixValue = Math.Max(maxMatrixValue, Double.IsPositiveInfinity(matrixValues[i][j]) ? 0 : matrixValues[i][j]); } } for (int i = 0; i < xLength; i++) { for (int j = 0; j < yLength; j++) { var value = matrixValues[i][j]; var isValuePositiveInfinity = Double.IsPositiveInfinity(value); var intensityBytes = isValuePositiveInfinity ? new byte[] { 0, 0, 0 } : GetFauxColourRgbIntensity(value, 0, maxMatrixValue); //var intensityByte = (byte)(255 - Math.Floor(255 * intensity)); plotModel.Annotations.Add(new PolygonAnnotation { Points = new[] { new DataPoint(i - 0.5, j - 0.5), new DataPoint(i + 0.5, j - 0.5), new DataPoint(i + 0.5, j + 0.5), new DataPoint(i - 0.5, j + 0.5), }, StrokeThickness = 0, Selectable = false, Layer = AnnotationLayer.BelowAxes, Fill = OxyColor.FromArgb(255, intensityBytes[0], intensityBytes[1], intensityBytes[2]), }); } } for (int i = 0; i < 30; i++) { var intensityBytes = GetFauxColourRgbIntensity(i, 0, 29); plotModel.Annotations.Add(new RectangleAnnotation { MinimumX = -39, MaximumX = -25, MinimumY = -i - 6, MaximumY = -i - 5, Selectable = false, Fill = OxyColor.FromArgb(255, intensityBytes[0], intensityBytes[1], intensityBytes[2]) }); } plotModel.Annotations.Add(new TextAnnotation { Position = new DataPoint(-24, -5), HorizontalAlignment = HorizontalTextAlign.Left, VerticalAlignment = VerticalTextAlign.Middle, StrokeThickness = 0, Text = "0" }); plotModel.Annotations.Add(new TextAnnotation { Position = new DataPoint(-24, -34), HorizontalAlignment = HorizontalTextAlign.Left, VerticalAlignment = VerticalTextAlign.Middle, StrokeThickness = 0, Text = String.Format("{0:0.00}", maxMatrixValue), }); } var matrixPathSeries = new LineSeries("Path") { StrokeThickness = 1, Color = OxyColors.Red, }; for (int i = 0; i < dtwPath.Length; i++) { matrixPathSeries.Points.Add(new DataPoint(dtwPath[i].Item1, dtwPath[i].Item2)); } plotModel.Series.Add(matrixPathSeries); var seriesMatrixScale = (xLength + yLength) * 0.05; for (int variableIndex = 0; variableIndex < Dtw.SeriesVariables.Length; variableIndex++) { var variableA = Dtw.SeriesVariables[variableIndex]; var variableASeries = variableA.OriginalXSeries; var variableB = Dtw.SeriesVariables[variableIndex]; var variableBSeries = variableB.OriginalYSeries; var minSeriesA = variableASeries.Min(); var maxSeriesA = variableASeries.Max(); var normalizedSeriesA = variableASeries.Select(x => (x - minSeriesA) / (maxSeriesA - minSeriesA)).ToList(); var matrixSeriesA = new LineSeries(variableA.VariableName); for (int i = 0; i < normalizedSeriesA.Count; i++) { matrixSeriesA.Points.Add(new DataPoint(i, (-1 + normalizedSeriesA[i]) * seriesMatrixScale - 1 - seriesMatrixScale * (variableIndex + 1))); } plotModel.Series.Add(matrixSeriesA); var minSeriesB = variableBSeries.Min(); var maxSeriesB = variableBSeries.Max(); var normalizedSeriesB = variableBSeries.Select(x => (x - minSeriesB) / (maxSeriesB - minSeriesB)).ToList(); var matrixSeriesB = new LineSeries(variableB.VariableName); for (int i = 0; i < normalizedSeriesB.Count; i++) { matrixSeriesB.Points.Add(new DataPoint(-normalizedSeriesB[i] * seriesMatrixScale - 1 - seriesMatrixScale * (variableIndex + 1), i)); } plotModel.Series.Add(matrixSeriesB); } plotModel.Axes.Add(new LinearAxis(AxisPosition.Bottom, " Series A") { Maximum = Math.Max(xLength, yLength), PositionAtZeroCrossing = true }); plotModel.Axes.Add(new LinearAxis(AxisPosition.Left, " Series B") { Maximum = Math.Max(xLength, yLength), PositionAtZeroCrossing = true }); MatrixPlot.Model = plotModel; }
void UpdateData() { if (plotModel == null) { return; } gridData.Rows.Clear(); plotModel.Series.Clear(); plotModel.Annotations.Clear(); plotHisto.Series.Clear(); int step = boxRestart.SelectedIndex; string keyword = listKeywords.SelectedItem.ToString(); // // _ = new List<Tuple<string, float, float>>(); List <Tuple <string, float, float> > data; if (listGroups.SelectedItem.ToString() == "(All)") { data = model.GetDataByKeywordAndDate(keyword, step); } else { string selected_pad = listGroups.SelectedItem.ToString(); data = model.GetDataByPadKeywordAndDate(selected_pad, keyword, step); } plotModel.Title = keyword.ToUpper(); int row = -1; int over20 = 0; int over10 = 0; int less10 = 0; int sum = 0; float max = 0; float relvalue = 0; float absvalue = 0; plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.None, MarkerType = MarkerType.Circle, MarkerFill = Color.Orange.ToOxyColor(), MarkerStroke = Color.Black.ToOxyColor(), MarkerSize = 3 }); foreach (Tuple <string, float, float> item in data) { if ((item.Item2 != 0.00) && (item.Item3 != 0.00)) { row = gridData.Rows.Add(); gridData[0, row].Value = item.Item1; gridData[1, row].Value = item.Item2; gridData[2, row].Value = item.Item3; absvalue = item.Item2 - item.Item3; relvalue = 100 * (item.Item2 - item.Item3) / item.Item3; gridData[3, row].Value = absvalue; gridData[4, row].Value = relvalue; // Критерии if (ActiveCondition == TypeCondition.Relative) { if (Math.Abs(relvalue) <= FirstCond) { less10++; } if ((Math.Abs(relvalue) > FirstCond) && (Math.Abs(relvalue) <= SecondCond)) { over10++; } if (Math.Abs(relvalue) > SecondCond) { over20++; } } if (ActiveCondition == TypeCondition.Absolute) { if (Math.Abs(absvalue) <= FirstCond) { less10++; } if ((Math.Abs(absvalue) > FirstCond) && (Math.Abs(absvalue) <= SecondCond)) { over10++; } if (Math.Abs(absvalue) > SecondCond) { over20++; } } if (item.Item2 > max) { max = item.Item2; } if (item.Item3 > max) { max = item.Item3; } // // Точки на графике var pointAnnotation1 = new OxyPlot.Annotations.PointAnnotation(); pointAnnotation1.Fill = Color.Orange.ToOxyColor(); pointAnnotation1.StrokeThickness = 1; pointAnnotation1.Stroke = Color.Black.ToOxyColor(); pointAnnotation1.X = Convert.ToDouble(item.Item2); pointAnnotation1.Y = Convert.ToDouble(item.Item3); pointAnnotation1.Text = item.Item1; pointAnnotation1.FontSize = 9; plotModel.Annotations.Add(pointAnnotation1); } } sum = less10 + over10 + over20; if (sum > 0) { // Линия хорошей адаптации plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.Dot, Color = Color.Red.ToOxyColor(), MarkerType = MarkerType.None, }); ((LineSeries)plotModel.Series[1]).Points.Add(new DataPoint(0, 0)); ((LineSeries)plotModel.Series[1]).Points.Add(new DataPoint(max, max)); // Линия по первому условию plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.Dot, Color = Color.Green.ToOxyColor(), MarkerType = MarkerType.None, }); plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.Dot, Color = Color.Green.ToOxyColor(), MarkerType = MarkerType.None, }); plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.Dot, Color = Color.Blue.ToOxyColor(), MarkerType = MarkerType.None, }); plotModel.Series.Add(new LineSeries { LineStyle = LineStyle.Dot, Color = Color.Blue.ToOxyColor(), MarkerType = MarkerType.None, }); if (ActiveCondition == TypeCondition.Relative) { ((LineSeries)plotModel.Series[2]).Points.Add(new DataPoint(0, 0)); ((LineSeries)plotModel.Series[2]).Points.Add(new DataPoint(max, (100 + FirstCond) * 0.01 * max)); ((LineSeries)plotModel.Series[3]).Points.Add(new DataPoint(0, 0)); ((LineSeries)plotModel.Series[3]).Points.Add(new DataPoint(max, (100 - FirstCond) * 0.01 * max)); ((LineSeries)plotModel.Series[4]).Points.Add(new DataPoint(0, 0)); ((LineSeries)plotModel.Series[4]).Points.Add(new DataPoint(max, (100 + SecondCond) * 0.01 * max)); ((LineSeries)plotModel.Series[5]).Points.Add(new DataPoint(0, 0)); ((LineSeries)plotModel.Series[5]).Points.Add(new DataPoint(max, (100 - SecondCond) * 0.01 * max)); plotHisto.Axes[0].Title = "Relative Deviation"; ((CategoryAxis)plotHisto.Axes[0]).ItemsSource = new[] { "<" + FirstCond + "%", FirstCond + "-" + SecondCond + " %", ">" + SecondCond + "%" }; } if (ActiveCondition == TypeCondition.Absolute) { ((LineSeries)plotModel.Series[2]).Points.Add(new DataPoint(0, FirstCond)); ((LineSeries)plotModel.Series[2]).Points.Add(new DataPoint(max, max + FirstCond)); ((LineSeries)plotModel.Series[3]).Points.Add(new DataPoint(0, -FirstCond)); ((LineSeries)plotModel.Series[3]).Points.Add(new DataPoint(max, max - FirstCond)); ((LineSeries)plotModel.Series[4]).Points.Add(new DataPoint(0, SecondCond)); ((LineSeries)plotModel.Series[4]).Points.Add(new DataPoint(max, max + SecondCond)); ((LineSeries)plotModel.Series[5]).Points.Add(new DataPoint(0, -SecondCond)); ((LineSeries)plotModel.Series[5]).Points.Add(new DataPoint(max, max - SecondCond)); plotHisto.Axes[0].Title = "Absolute Deviation"; ((CategoryAxis)plotHisto.Axes[0]).ItemsSource = new[] { "<" + FirstCond, FirstCond + "-" + SecondCond, ">" + SecondCond }; } plotHisto.Series.Add(new BarSeries { FillColor = OxyColor.FromArgb(255, 255, 120, 0), }); ((BarSeries)plotHisto.Series[0]).Items.Add(new BarItem { Value = less10 }); ((BarSeries)plotHisto.Series[0]).Items.Add(new BarItem { Value = over10 }); ((BarSeries)plotHisto.Series[0]).Items.Add(new BarItem { Value = over20 }); } plotModel.InvalidatePlot(true); plotHisto.InvalidatePlot(true); }
public static PlotModel ScatterSeries() { var plotModel1 = new PlotModel { Title = "Scatterseries not rendered at specific plot sizes", PlotMargins = new OxyThickness(50, 5, 5, 50), Padding = new OxyThickness(0), PlotAreaBorderThickness = new OxyThickness(1, 1, 1, 1), PlotAreaBorderColor = OxyColors.Black, TextColor = OxyColors.Black, LegendOrientation = LegendOrientation.Horizontal, LegendPosition = LegendPosition.TopRight, LegendMargin = 0 }; plotModel1.Axes.Add(new LinearAxis { IsAxisVisible = true, Title = "X", Position = AxisPosition.Bottom, TickStyle = TickStyle.Outside, TicklineColor = OxyColors.Black, Minimum = 0, MaximumPadding = 0.05 }); plotModel1.Axes.Add(new LogarithmicAxis { MinimumPadding = 0.05, MaximumPadding = 0.1, Title = "Y", Position = AxisPosition.Left, TickStyle = TickStyle.Outside, TicklineColor = OxyColors.Black, MajorGridlineColor = OxyColors.Black, MajorGridlineStyle = LineStyle.Solid }); var referenceCurve = new LineSeries { Title = "Reference", Smooth = true, Color = OxyColor.FromArgb(255, 89, 128, 168) }; var upperBoundary = new LineSeries { LineStyle = LineStyle.Dot, Color = OxyColors.LightGray, Smooth = true, Title = string.Empty }; var lowerBoundary = new LineSeries { LineStyle = LineStyle.Dot, Color = OxyColors.LightGray, Smooth = true, Title = "+/- 15 %" }; // Series that holds and formats points inside of the boundary var inBoundaryResultLine = new ScatterSeries { Title = "actual", MarkerFill = OxyColors.Black, MarkerSize = 4, MarkerStroke = OxyColors.White, MarkerType = MarkerType.Circle }; // Series that holds and formats points outside of the boundary var outBoundaryResultLine = new ScatterSeries { Title = "not permissible deviation", MarkerFill = OxyColors.Red, MarkerSize = 4, MarkerStroke = OxyColors.White, MarkerType = MarkerType.Circle }; // Just some random data to fill the series: var referenceValues = new[] { double.NaN, 0.985567558024852, 0.731704530257957, 0.591109071735532, 0.503627816316065, 0.444980686815776, 0.403576666032678, 0.373234299823915, 0.350375591667333, 0.332795027566349, 0.319063666439909, 0.30821748743148, 0.299583943726489, 0.292680371378706, 0.287151885046283, 0.282732008216725, 0.279216923371711, 0.276557880999918 }; var actualValues = new[] { double.NaN, 0.33378346040897, 1.09868427497967, 0.970771068054048, 0.739778217457323, 0.582112938330166, 0.456962500853806, 0.37488740614826, 0.330272509496142, 0.334461549522006, 0.30989175806678, 0.286944862053553, 0.255895385950234, 0.231850970296068, 0.217579897050944, 0.217113227224437, 0.164759946945322, 0.0459134254747994 }; for (var index = 0; index <= 17; index++) { var referenceValue = referenceValues[index]; var lowerBound = referenceValue - (referenceValue * 0.15); var upperBound = referenceValue + (referenceValue * 0.15); referenceCurve.Points.Add(new DataPoint(index, referenceValue)); lowerBoundary.Points.Add(new DataPoint(index, lowerBound)); upperBoundary.Points.Add(new DataPoint(index, upperBound)); var actualValue = actualValues[index]; if (actualValue > lowerBound && actualValue < upperBound) { inBoundaryResultLine.Points.Add(new ScatterPoint(index, actualValue)); } else { outBoundaryResultLine.Points.Add(new ScatterPoint(index, actualValue)); } } plotModel1.Series.Add(referenceCurve); plotModel1.Series.Add(lowerBoundary); plotModel1.Series.Add(upperBoundary); plotModel1.Series.Add(outBoundaryResultLine); plotModel1.Series.Add(inBoundaryResultLine); return(plotModel1); }
public void InitPlot(string xAxis = "Time", string yAxis = "Viewers", string format = "HH:mm", bool relative = true) { if (PlotDataPoints == null) { PlotDataPoints = new List <KeyValuePair <string, KeyValuePair <double, double> > >(); } viewerChart = new PlotModel(); viewerChart.TextColor = OxyColor.FromRgb(175, 175, 175); viewerChart.PlotAreaBorderThickness = new OxyThickness(0); var valueAxisY = new OxyPlot.Axes.TimeSpanAxis { Position = OxyPlot.Axes.AxisPosition.Left, TicklineColor = OxyColor.FromRgb(125, 125, 155), Title = yAxis, FontSize = 26, TitleFontSize = 26, AxislineThickness = 3, MinorGridlineThickness = 5, MajorGridlineThickness = 5, MajorGridlineStyle = LineStyle.Solid, FontWeight = 700, TitleFontWeight = 700, AxislineStyle = LineStyle.Solid, AxislineColor = OxyColor.FromRgb(125, 125, 155) }; if (relative) { valueAxisY.Minimum = 0; } var valueAxisX = new OxyPlot.Axes.DateTimeAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, TicklineColor = OxyColor.FromRgb(125, 125, 155), Title = xAxis, FontSize = 26, TitleFontSize = 26, AxislineThickness = 3, MinorGridlineThickness = 5, MajorGridlineThickness = 5, MajorGridlineStyle = LineStyle.Solid, FontWeight = 700, TitleFontWeight = 700, AxislineStyle = LineStyle.Solid, AxislineColor = OxyColor.FromRgb(125, 125, 155), StringFormat = format }; viewerChart.Axes.Add(valueAxisY); viewerChart.Axes.Add(valueAxisX); viewerChart.LegendFontSize = 24; viewerChart.LegendPosition = LegendPosition.BottomCenter; viewerChart.LegendBorder = OxyColor.FromRgb(125, 125, 155); viewerChart.LegendBackground = OxyColor.FromArgb(200, 46, 49, 54); viewerChart.LegendTextColor = OxyColor.FromRgb(175, 175, 175); areaSeries = new List <OxyPlot.Series.AreaSeries>(); /*foreach (var plotPoint in PlotPoints) * { * AddValue(plotPoint.Key, plotPoint.Value, false); * }*/ if (PlotDataPoints.Count > 0) { PlotDataPoints = PlotDataPoints.Skip(Math.Max(0, PlotDataPoints.Count - 2000)).ToList(); StartTime = DateTimeAxis.ToDateTime(PlotDataPoints.First().Value.Key); foreach (var dataPoint in PlotDataPoints) { if (!MultipleLines) { AddValue(dataPoint.Key, dataPoint.Value.Value, DateTimeAxis.ToDateTime(dataPoint.Value.Key), false, relative); } else { AddValueSeperate(dataPoint.Key, dataPoint.Value.Value, DateTimeAxis.ToDateTime(dataPoint.Value.Key), false, relative); } } } }