-
Notifications
You must be signed in to change notification settings - Fork 204
/
LiveUpdate.cs
85 lines (69 loc) · 2.51 KB
/
LiveUpdate.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Views;
using Com.Syncfusion.Charts;
using Com.Syncfusion.Charts.Enums;
using System;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace SampleBrowser
{
public class LiveUpdate : SamplePage
{
private readonly ObservableCollection<DataPoint> data = new ObservableCollection<DataPoint>();
private readonly ObservableCollection<DataPoint> data2 = new ObservableCollection<DataPoint>();
private int wave1;
private int wave2 = 180;
private SfChart chart;
public override View GetSampleContent(Context context)
{
LoadData();
chart = new SfChart(context);
chart.SetBackgroundColor(Color.White);
chart.PrimaryAxis = new NumericalAxis() { ShowMajorGridLines = false };
chart.ColorModel.ColorPalette = ChartColorPalette.Natural;
var axis = new NumericalAxis {Minimum = -1.5, Maximum = 1.5, ShowMajorGridLines= false};
chart.SecondaryAxis = axis;
axis.LabelStyle.LabelsPosition = AxisElementPosition.Outside;
axis.TickPosition = AxisElementPosition.Outside;
var lineSeries = new FastLineSeries {ItemsSource = data, XBindingPath = "XValue", YBindingPath = "YValue" };
var fastLine = new FastLineSeries();
fastLine.ItemsSource = data2;
fastLine.XBindingPath = "XValue";
fastLine.YBindingPath = "YValue";
chart.Series.Add(fastLine);
chart.Series.Add(lineSeries);
UpdateData();
return chart;
}
private void LoadData()
{
for (var i = 0; i < 180; i++)
{
data.Add(new DataPoint(i, Math.Sin(wave1*(Math.PI/180.0))));
wave1++;
}
for (var i = 0; i < 180; i++)
{
data2.Add(new DataPoint(i, Math.Sin(wave2 * (Math.PI / 180.0))));
wave2++;
}
wave1 = data.Count;
}
private async void UpdateData()
{
while (true)
{
await Task.Delay(10);
data.RemoveAt(0);
data.Add(new DataPoint(wave1, Math.Sin(wave1*(Math.PI/180.0))));
wave1++;
data2.RemoveAt(0);
data2.Add(new DataPoint(wave1, Math.Sin(wave2 * (Math.PI / 180.0))));
wave2++;
}
}
}
}