private async Task GenerateUserChangeChart() { // Breaks the method into an async method so it can work in peace and be awaited. await Task.Delay(1).ConfigureAwait(false); // TODO: Add locking to this collection. As it grows, it will start to crash while generating the chart. var data = Data.UserChangeStats. ToList(). OrderBy(x => x.Second). GroupBy(x => x.Name). Select(x => new { x.Key, Points = x.Select(y => new DataPoint(y.Second, Math.Max(0.1, y.Value))).ToList(), }). ToList(); List <LineSeries> allSeries = new List <LineSeries>(); foreach (var singleSeries in data) { LineSeries series = new LineSeries { Title = singleSeries.Key, }; series.Points.AddRange(singleSeries.Points); allSeries.Add(series); } // This (partially?)fixes an issue where adding a lot of series will cause exceptions when refreshing the // chart. Locking on the sync root will allow us exclusive access to quickly update the charts data without // crossing the charts internal operations. It must be kept short though. lock (UserChangesPlot.SyncRoot) { UserChangesPlot.Series.Clear(); foreach (LineSeries series in allSeries) { UserChangesPlot.Series.Add(series); } } UserChangesPlot.InvalidatePlot(true); }
private void ResetUserChangesPlotButton_ClickHandler(object sender, RoutedEventArgs e) { UserChangesPlot.ResetAllAxes(); }