/Main/src/Xbap/DynamicDataDisplay.Xbap.Samples/Demos/v04/Markers/StockMarkersPage.xaml.cs
C# | 97 lines | 73 code | 15 blank | 9 comment | 3 complexity | 37e79681cce9215e578f30e68f9cb98a 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.Collections.ObjectModel; 15using Microsoft.Research.DynamicDataDisplay; 16 17namespace NewMarkersSample.Pages 18{ 19 /// <summary> 20 /// Interaction logic for StockMarkersPage.xaml 21 /// </summary> 22 public partial class StockMarkersPage : Page 23 { 24 public StockMarkersPage() 25 { 26 InitializeComponent(); 27 } 28 29 private readonly ObservableCollection<StockInfo> stockData = new ObservableCollection<StockInfo>(); 30 private Random rnd = new Random(); 31 32 private void Page_Loaded(object sender, RoutedEventArgs e) 33 { 34 // making both plotters' viewport connected 35 plotter.Viewport.SetBinding(Viewport2D.VisibleProperty, new Binding("Visible") { Source = plotter2.Viewport, Mode = BindingMode.TwoWay }); 36 37 DateTime now = DateTime.Now; 38 dateAxis.SetConversion(1000, now, 1010, now.AddDays(10)); 39 dateAxis2.SetConversion(1000, now, 1010, now.AddDays(10)); 40 41 // setting visible region in terms of <DateTime, double> rectangle, not usual <double, double> one. 42 var genericPlotter = plotter.GetGenericPlotter<DateTime, double>(); 43 genericPlotter.ViewportRect = new GenericRect<DateTime, double>(DateTime.Now.AddDays(-2), -2.5, DateTime.Now.AddDays(60), 2.5); 44 45 // initialialize stock data 46 const int count = 35; 47 for (int i = 0; i < count; i++) 48 { 49 stockData.Add(CreateNewStockInfo()); 50 } 51 52 // this will make charts to display data, 53 // as they are inside window, and their DataContext properties will change as Window's DataContext changes. 54 // This happens because DataContextProperty inherits its value from parent in LogicalTree. 55 DataContext = stockData; 56 } 57 58 private int daysCounter = 0; 59 private StockInfo CreateNewStockInfo() 60 { 61 double open; 62 if (stockData.Count == 0) 63 { 64 open = rnd.NextDouble(); 65 } 66 else 67 { 68 open = stockData[stockData.Count - 1].Close; 69 } 70 71 double close = rnd.NextDouble(); 72 73 double low = Math.Min(open, close) - rnd.NextDouble(); 74 double high = Math.Max(open, close) + rnd.NextDouble(); 75 76 DateTime time = DateTime.Now.Date.AddDays(daysCounter++); 77 78 StockInfo info = new StockInfo { Open = open, Close = close, High = high, Low = low, Time = time }; 79 return info; 80 } 81 82 private void addStockInfo_Click(object sender, RoutedEventArgs e) 83 { 84 stockData.Add(CreateNewStockInfo()); 85 } 86 } 87 88 public sealed class StockInfo 89 { 90 public double Open { get; set; } 91 public double Close { get; set; } 92 public double High { get; set; } 93 public double Low { get; set; } 94 95 public DateTime Time { get; set; } 96 } 97}