|
|
|
@ -14,6 +14,7 @@ using System.Windows.Media; |
|
|
|
|
using System.Windows.Media.Imaging; |
|
|
|
|
using System.Windows.Navigation; |
|
|
|
|
using System.Windows.Shapes; |
|
|
|
|
using System.Timers; |
|
|
|
|
|
|
|
|
|
namespace LiveChartPractice |
|
|
|
|
{ |
|
|
|
@ -22,27 +23,57 @@ namespace LiveChartPractice |
|
|
|
|
/// </summary> |
|
|
|
|
public partial class MainWindow : Window |
|
|
|
|
{ |
|
|
|
|
private Timer _timer; |
|
|
|
|
private Random _rand; |
|
|
|
|
|
|
|
|
|
private SampleData _data; |
|
|
|
|
|
|
|
|
|
public MainWindow() |
|
|
|
|
{ |
|
|
|
|
InitializeComponent(); |
|
|
|
|
InitInstance(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void InitInstance() |
|
|
|
|
{ |
|
|
|
|
_data = this.DataContext as SampleData; |
|
|
|
|
|
|
|
|
|
_timer = new Timer(); |
|
|
|
|
_timer.Elapsed -= _timer_Elapsed; |
|
|
|
|
_timer.Elapsed += _timer_Elapsed; |
|
|
|
|
_timer.Interval = 100; |
|
|
|
|
_timer.Stop(); |
|
|
|
|
|
|
|
|
|
_rand = new Random(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void btnSeriesAdd_Click(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
SampleData data = this.DataContext as SampleData; |
|
|
|
|
if (data == null) |
|
|
|
|
if (_data == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Random rand = new Random(); |
|
|
|
|
data.SeriesCollection.Add(new LineSeries |
|
|
|
|
_data.SeriesCollection.Add(new LineSeries |
|
|
|
|
{ |
|
|
|
|
Title = $"Series {data.SeriesCollection.Count + 1}", |
|
|
|
|
Values = new ChartValues<double> { rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8) }, |
|
|
|
|
LineSmoothness = rand.Next(0, 2), //0: straight lines, 1: really smooth lines |
|
|
|
|
Title = $"Series {_data.SeriesCollection.Count + 1}", |
|
|
|
|
Values = new ChartValues<double> { _rand.Next(1, 8), _rand.Next(1, 8), _rand.Next(1, 8), _rand.Next(1, 8), _rand.Next(1, 8) }, |
|
|
|
|
LineSmoothness = _rand.Next(0, 2), //0: straight lines, 1: really smooth lines |
|
|
|
|
//PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"), |
|
|
|
|
//PointGeometrySize = 50, |
|
|
|
|
//PointForeground = Brushes.Gray |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void btnRT_Click(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (_data == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
_timer.Start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void _timer_Elapsed(object? sender, ElapsedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
_data.SingleSeries[0].Values.Add(_rand.NextDouble() * 10.0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|