-
Notifications
You must be signed in to change notification settings - Fork 601
/
Copy pathViewModel.cs
46 lines (38 loc) · 1.23 KB
/
ViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.Kernel.Events;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.Events.AddPointOnClick;
public partial class ViewModel
{
public ObservableCollection<ObservablePoint> Points { get; set; }
public ISeries[] SeriesCollection { get; set; }
public ViewModel()
{
Points = [
new(0, 5),
new(3, 8),
new(7, 9)
];
SeriesCollection = [
new LineSeries<ObservablePoint>
{
Values = Points,
Fill = null,
DataPadding = new LiveChartsCore.Drawing.LvcPoint(5, 5)
}
];
}
[RelayCommand]
public void PointerDown(PointerCommandArgs args)
{
var chart = (ICartesianChartView)args.Chart;
// scales the UI coordinates to the corresponding data in the chart.
var scaledPoint = chart.ScalePixelsToData(args.PointerPosition);
// finally add the new point to the data in our chart.
Points.Add(new ObservablePoint(scaledPoint.X, scaledPoint.Y));
}
}