You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

using LiveCharts.Wpf;
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
2 years ago
using System.Timers;
namespace LiveChartPractice
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
2 years ago
private Timer _timer;
private Random _rand;
private SampleData _data;
public MainWindow()
{
InitializeComponent();
2 years ago
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)
{
2 years ago
if (_data == null)
return;
2 years ago
_data.SeriesCollection.Add(new LineSeries
{
2 years ago
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
});
}
2 years ago
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);
}
}
}