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