diff --git a/PacticeSolution/LiveChartPractice/MainWindow.xaml b/PacticeSolution/LiveChartPractice/MainWindow.xaml
index 56f6532..266dcaf 100644
--- a/PacticeSolution/LiveChartPractice/MainWindow.xaml
+++ b/PacticeSolution/LiveChartPractice/MainWindow.xaml
@@ -18,7 +18,7 @@
-
+
@@ -29,12 +29,19 @@
-
-
+
+
+
+
+
+
+
+
+
-
+
diff --git a/PacticeSolution/LiveChartPractice/MainWindow.xaml.cs b/PacticeSolution/LiveChartPractice/MainWindow.xaml.cs
index ac66c1f..108c3ab 100644
--- a/PacticeSolution/LiveChartPractice/MainWindow.xaml.cs
+++ b/PacticeSolution/LiveChartPractice/MainWindow.xaml.cs
@@ -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
///
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 { 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 { _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);
+ }
}
}
diff --git a/PacticeSolution/LiveChartPractice/SampleData.cs b/PacticeSolution/LiveChartPractice/SampleData.cs
index 8bd1957..e14bde8 100644
--- a/PacticeSolution/LiveChartPractice/SampleData.cs
+++ b/PacticeSolution/LiveChartPractice/SampleData.cs
@@ -13,6 +13,7 @@ namespace LiveChartPractice
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func YFormatter { get; set; }
+ public SeriesCollection SingleSeries { get; set; }
public SampleData()
{
@@ -40,6 +41,16 @@ namespace LiveChartPractice
this.Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May" };
this.YFormatter = value => value.ToString("C");
+
+ this.SingleSeries = new SeriesCollection()
+ {
+ new LineSeries()
+ {
+ Title = "Series",
+ Values = new ChartValues(),
+ LineSmoothness = 0,
+ }
+ };
}
}
}