private LineSeries GenPoints() { OxyPlot.Series.LineSeries series = new LineSeries(); foreach (var price in XF.Quotes) { series.Points.Add(new DataPoint(DateTimeAxis.ToDouble(price.Date), LinearAxis.ToDouble(price.Close))); } return(series); }
private void SetupPlotModel() { PlotModel.Series.Clear(); PlotModel.Axes.Clear(); PlotModel.Title = "Ilość zachorowań"; PlotModel.LegendTitle = "Legenda"; PlotModel.LegendOrientation = LegendOrientation.Horizontal; PlotModel.LegendPosition = LegendPosition.TopRight; PlotModel.LegendBackground = OxyColor.FromAColor(200, OxyColors.White); PlotModel.LegendBorder = OxyColors.Black; var yearAxis = new LinearAxis() { Position = AxisPosition.Bottom, Title = "Rok", MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }; var valueAxis = new LinearAxis() { Position = AxisPosition.Left, Title = "Liczba zachorowań", MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }; var collectionYear = DataList.Select(x => x.Year).Distinct().ToList(); var lineSeriesYearNumber = new LineSeries { StrokeThickness = 2, MarkerSize = 1, Color = OxyColors.Red, RenderInLegend = true, Title = "Ilość zachorowań" }; foreach (var item in collectionYear) { lineSeriesYearNumber.Points.Add(new DataPoint(LinearAxis.ToDouble(item), DataList.Where(x => x.Year.Equals(item)).Select(x => x.Number).Sum())); } PlotModel.Series.Add(lineSeriesYearNumber); PlotModel.Axes.Add(yearAxis); PlotModel.Axes.Add(valueAxis); }
private void UpdateLineSeries(float value, DateTime date) { var series = _plotModel.Series[0] as LineSeries; var newDataPoint = new DataPoint(DateTimeAxis.ToDouble(date), LinearAxis.ToDouble(value)); //show only last 20 datapoints if (series.Points.Count > 20) { series.Points.RemoveAt(0); } series.Points.Add(newDataPoint); _plotModel.InvalidatePlot(true); }
private void SetupPlotModel2() { PlotModel2.Series.Clear(); PlotModel2.Axes.Clear(); PlotModel2.Title = "Ilość zachorowań ze względu na grupy wiekowe"; PlotModel2.LegendTitle = "Legenda"; PlotModel2.LegendOrientation = LegendOrientation.Horizontal; PlotModel2.LegendPosition = LegendPosition.TopRight; PlotModel2.LegendBackground = OxyColor.FromAColor(200, OxyColors.White); PlotModel2.LegendBorder = OxyColors.Black; var yearAxis = new LinearAxis() { Position = AxisPosition.Bottom, Title = "Rok", MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }; var valueAxis = new LinearAxis() { Position = AxisPosition.Left, Title = "Liczba zachorowań", MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }; var collectionYear = DataList.Select(x => x.Year).Distinct().ToList(); var collectionAge = DataList.Select(x => x.Age).Distinct().ToList(); var lineSeriesAges = new LineSeries[collectionAge.Count]; foreach (var age in collectionAge) { var series = new LineSeries() { Title = age, }; foreach (var year in collectionYear) { series.Points.Add(new DataPoint(LinearAxis.ToDouble(year), LinearAxis.ToDouble(DataList.Where(x => x.Year.Equals(year) && x.Age.Equals(age)).Select(x => x.Number).Sum()))); } //plotModel2.Axes.Add(valueAxis); //plotModel2.Axes.Add(yearAxis); PlotModel2.Series.Add(series); } PlotModel2.Axes.Add(yearAxis); PlotModel2.Axes.Add(valueAxis); }
private void HandleNewStockPrice(StockPriceMessage message) { if (_series.ContainsKey(message.StockSymbol)) { var series = _series[message.StockSymbol]; var newDataPoint = new DataPoint(DateTimeAxis.ToDouble(message.Date), LinearAxis.ToDouble(message.StockPrice)); // Keep the last 10 data points on graph if (series.Points.Count > 10) { series.Points.RemoveAt(0); } series.Points.Add(newDataPoint); RefreshChart(); } }
private void DataGridPriceDynamic_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataGrid dgv = (DataGrid)sender; PriceDynamicModel model = (PriceDynamicModel)dgv.SelectedItem; MainChart.Model.Series.Clear(); MainChart.Model.Axes.Clear(); MainChart.Model.Title = "Товар не выбран"; MainChart.Model.InvalidatePlot(true); if (model != null) { bool isDaily = (bool)CheckBoxChoosenDaily.IsChecked; PropertyInfo[] props = model.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).ToArray(); List <int> prices = new List <int>(); foreach (PropertyInfo item in props) { if (item.Name.Contains("Date") && item.Name.Length > 4 && item.Name.Length < 7) { try { int?a = (int)item.GetValue(model); prices.Add(a ?? 0); } catch (Exception) { } } } List <DateTime> dates = dbLoader.GetTopStatistic(isDaily, prices.Count).Select(x => x.CreationDate).ToList(); if (dates.Count != 0 && dates.Count == prices.Count) { MainChart.Model.Axes.Add(new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = DateTimeAxis.ToDouble(dates.First().Date), Maximum = DateTimeAxis.ToDouble(dates.Last().Date), StringFormat = "dd-MM-yyyy", MinimumMinorStep = 1, MinimumMajorStep = 1 }); MainChart.Model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = LinearAxis.ToDouble(prices.Min() * 0.95), Maximum = LinearAxis.ToDouble(prices.Max() * 1.05), MinimumMinorStep = 1 }); var areaSeries = new AreaSeries(); if (prices.Count == dates.Count) { for (int i = 0; i < prices.Count; i++) { DataPoint dp = new DataPoint(DateTimeAxis.ToDouble(dates[i]), (double)prices[i]); areaSeries.Points.Add(dp); } MainChart.Model.Series.Add(areaSeries); MainChart.Model.Title = model.Name; } MainChart.Model.InvalidatePlot(true); } } }