/Main/src/Samples/Simple/DynamicPointAddSample/Window1.xaml.cs
C# | 71 lines | 54 code | 9 blank | 8 comment | 1 complexity | 4197e49c476fd97de85eb7f41ca558af MD5 | raw file
Possible License(s): CC-BY-SA-3.0
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Windows; 6using System.Windows.Controls; 7using System.Windows.Data; 8using System.Windows.Documents; 9using System.Windows.Input; 10using System.Windows.Media; 11using System.Windows.Media.Imaging; 12using System.Windows.Navigation; 13using System.Windows.Shapes; 14using System.Windows.Threading; 15using System.Collections.ObjectModel; 16 17using Microsoft.Research.DynamicDataDisplay; 18using Microsoft.Research.DynamicDataDisplay.DataSources; 19 20namespace DynamicPointAddSample 21{ 22 /// <summary> 23 /// Interaction logic for Window1.xaml 24 /// </summary> 25 public partial class Window1 : Window 26 { 27 public Window1() 28 { 29 InitializeComponent(); 30 31 Loaded += new RoutedEventHandler(Window1_Loaded); 32 } 33 34 private DispatcherTimer timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(4) }; 35 private ObservableCollection<Point> data = new ObservableCollection<Point>(); 36 private int x = 0; 37 private Random rnd = new Random(); 38 39 private void Window1_Loaded(object sender, RoutedEventArgs e) 40 { 41 // initial collection content 42 for (int i = 0; i < 10000; i++) 43 { 44 AddNextPoint(); 45 } 46 47 // switching off approximate content bounds' comparison, as this can cause improper behavior. 48 plotter.Viewport.UseApproximateContentBoundsComparison = false; 49 // adding line chart to plotter 50 var line = plotter.AddLineGraph(data.AsDataSource()); 51 // again switching off approximate content bounds' comparison - now in coercion method of Viewport2D.ContentBounds attached dependency property. 52 Viewport2D.SetUsesApproximateContentBoundsComparison(line, false); 53 54 // simulating data being received from external source on each timer tick 55 timer.Tick += new EventHandler(timer_Tick); 56 timer.Start(); 57 } 58 59 void timer_Tick(object sender, EventArgs e) 60 { 61 AddNextPoint(); 62 plotter.FitToView(); 63 } 64 65 private void AddNextPoint() 66 { 67 Point p = new Point { X = x++, Y = rnd.NextDouble() }; 68 data.Add(p); 69 } 70 } 71}