PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/Samples/v0.2/Markers/Window1.xaml.cs

#
C# | 80 lines | 54 code | 12 blank | 14 comment | 1 complexity | 1605919a68873e0451cc9fd5a4dfaaab MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using Microsoft.Research.DynamicDataDisplay;
  5. using Microsoft.Research.DynamicDataDisplay.DataSources;
  6. using Microsoft.Research.DynamicDataDisplay.PointMarkers;
  7. namespace SimpleMarkers
  8. {
  9. /// <summary>
  10. /// Interaction logic for Window1.xaml
  11. /// </summary>
  12. public partial class Window1 : Window
  13. {
  14. public Window1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void Window_Loaded(object sender, RoutedEventArgs e)
  19. {
  20. // Prepare data in arrays
  21. const int N = 100;
  22. double[] x = new double[N];
  23. double[] cs = new double[N];
  24. double[] sn = new double[N];
  25. for (int i = 0; i < N; i++)
  26. {
  27. x[i] = i * 0.1;
  28. cs[i] = Math.Sin(x[i]);
  29. sn[i] = Math.Cos(x[i]);
  30. }
  31. // Add data sources:
  32. // 3 partial data sources, containing each of arrays
  33. var snDataSource = new EnumerableDataSource<double>(sn);
  34. snDataSource.SetYMapping(y => y);
  35. var xDataSource = new EnumerableDataSource<double>(x);
  36. xDataSource.SetXMapping(lx => lx);
  37. var csDataSource = new EnumerableDataSource<double>(cs);
  38. csDataSource.SetYMapping(y => y);
  39. var csqDataSource = new EnumerableDataSource<double>(cs);
  40. csqDataSource.SetYMapping(y => y * y);
  41. // 2 composite data sources and 2 charts respectively:
  42. // creating composite data source
  43. CompositeDataSource compositeDataSource1 = new CompositeDataSource(xDataSource, snDataSource);
  44. // adding graph to plotter
  45. plotter.AddLineGraph(compositeDataSource1,
  46. new Pen(Brushes.DarkGoldenrod, 3),
  47. new CirclePointMarker { Size = 10, Fill = Brushes.Red },
  48. new PenDescription("Sin"));
  49. // creating composite data source for cs values
  50. CompositeDataSource compositeDataSource2 = new CompositeDataSource(xDataSource, csDataSource);
  51. // Adding second graph to plotter
  52. plotter.AddLineGraph(compositeDataSource2,
  53. new Pen(Brushes.Blue, 3),
  54. new TrianglePointMarker { Size = 20, Fill = Brushes.Blue },
  55. new PenDescription("Cos"));
  56. // creating composite data source for cs^2 values
  57. CompositeDataSource compositeDataSource3 = new CompositeDataSource(xDataSource, csqDataSource);
  58. // Adding thirs graph to plotter
  59. Pen dashed = new Pen(Brushes.Magenta, 3);
  60. dashed.DashStyle = DashStyles.Dot;
  61. plotter.AddLineGraph(compositeDataSource3,
  62. dashed,
  63. new PenDescription("Cos^2"));
  64. // Force evertyhing plotted to be visible
  65. plotter.FitToView();
  66. }
  67. }
  68. }