From 257a21321e1b932e32634bd8ec26e2261dada8c8 Mon Sep 17 00:00:00 2001 From: syneffort Date: Tue, 21 May 2024 10:11:49 +0900 Subject: [PATCH] RT chart --- OxyPlotExample/GettingStarted/MainWindow.xaml | 2 + .../ViewModels/MainViewModel.cs | 3 + .../ViewModels/MainViewModel2.cs | 15 +++-- .../ViewModels/MainViewModel3.cs | 67 +++++++++++++++++++ .../Views/MainViewControl3.xaml | 26 +++++++ .../Views/MainViewControl3.xaml.cs | 28 ++++++++ 6 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs create mode 100644 OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml create mode 100644 OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml.cs diff --git a/OxyPlotExample/GettingStarted/MainWindow.xaml b/OxyPlotExample/GettingStarted/MainWindow.xaml index 7fb12a8..63662fc 100644 --- a/OxyPlotExample/GettingStarted/MainWindow.xaml +++ b/OxyPlotExample/GettingStarted/MainWindow.xaml @@ -13,9 +13,11 @@ + + diff --git a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel.cs b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel.cs index 6596d6c..5184602 100644 --- a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel.cs +++ b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using OxyPlot; using OxyPlot.Series; using System; @@ -6,6 +7,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Timers; +using System.Windows; namespace GettingStarted.ViewModels { diff --git a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel2.cs b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel2.cs index 436411f..0a75884 100644 --- a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel2.cs +++ b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel2.cs @@ -1,10 +1,12 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using OxyPlot; using System; using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; +using System.Timers; +using System.Windows; namespace GettingStarted.ViewModels { @@ -22,12 +24,11 @@ namespace GettingStarted.ViewModels Points = new List() { new DataPoint(0, 4), - new DataPoint(10, 13), - new DataPoint(20, 15), - new DataPoint(30, 16), - new DataPoint(40, 12), - new DataPoint(50, 12) - + new DataPoint(1, 13), + new DataPoint(2, 15), + new DataPoint(3, 16), + new DataPoint(4, 12), + new DataPoint(5, 12) }; } } diff --git a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs new file mode 100644 index 0000000..7521d5c --- /dev/null +++ b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs @@ -0,0 +1,67 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using OxyPlot.Series; +using OxyPlot; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows; + +namespace GettingStarted.ViewModels +{ + internal partial class MainViewModel3 : ObservableObject + { + [ObservableProperty] + private PlotModel _myModel; + + + [ObservableProperty] + private LineSeries _lineSeries; + + + public MainViewModel3() + { + MyModel = new PlotModel() { Title = "Getting Started with RT Plot" }; + LineSeries = new LineSeries() { Title = "Dynamic Data" }; + + MyModel.Series.Add(LineSeries); + + _timer = new System.Timers.Timer(); + _timer.Interval = 50; + _timer.Elapsed -= _timer_Elapsed; + _timer.Elapsed += _timer_Elapsed; + } + + private int _lastX = 0; + private void _timer_Elapsed(object? sender, ElapsedEventArgs e) + { + Application.Current.Dispatcher.Invoke(() => + { + LineSeries.Points.Add(new DataPoint(_lastX, Math.Sin(_lastX * 0.1))); + MyModel.InvalidatePlot(true); + _lastX++; + }); + } + + private bool _isTimerStarted = false; + private System.Timers.Timer _timer; + + [RelayCommand] + private void FlipTimer() + { + if (!_isTimerStarted) + { + _timer.Start(); + _isTimerStarted = true; + } + else + { + _timer.Stop(); + _isTimerStarted = false; + } + } + } +} diff --git a/OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml b/OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml new file mode 100644 index 0000000..d942813 --- /dev/null +++ b/OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + +