public BasicTest()
        {
            // uses the sample basics from http://oxyplot.org/doc/HelloWpfXaml.html
            var Points = new List <DataPoint>
            {
                new DataPoint(0, 4),
                new DataPoint(10, 13),
                new DataPoint(20, 15),
                new DataPoint(30, 16),
                new DataPoint(40, 12),
                new DataPoint(50, 12)
            };

            var m = new PlotModel("Titleee");

            m.PlotType = PlotType.XY;

            var s = new LineSeries();

            s.ItemsSource = Points;
            m.Series.Add(s);

            var opv = new OxyPlotView {
                WidthRequest    = 300, HeightRequest = 300,
                BackgroundColor = Color.Aqua
            };

            opv.Model = m;

            Content = new StackLayout {
                Children =
                {
                    new Label {
                        Text              = "Hello, Oxyplot!",
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                    },
                    opv,
                    new Label {
                        Text              = "http://oxyplot.org/doc/HelloWpfXaml.html",
                        Font              = Font.SystemFontOfSize(NamedSize.Small),
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                    },
                }
            };
        }
Esempio n. 2
0
		public BasicTest ()
		{
			// uses the sample basics from http://oxyplot.org/doc/HelloWpfXaml.html
			var Points = new List<DataPoint>
			{
				new DataPoint(0, 4),
				new DataPoint(10, 13),
				new DataPoint(20, 15),
				new DataPoint(30, 16),
				new DataPoint(40, 12),
				new DataPoint(50, 12)
			};

			var m = new PlotModel ("Titleee");
			m.PlotType = PlotType.XY;

			var s = new LineSeries ();
			s.ItemsSource = Points;
			m.Series.Add (s);

			var opv = new OxyPlotView {
				WidthRequest = 300, HeightRequest = 300,
				BackgroundColor = Color.Aqua
			};
			opv.Model = m;

			Content = new StackLayout {
				Children = {
						new Label {
						Text = "Hello, Oxyplot!",
						VerticalOptions = LayoutOptions.CenterAndExpand,
						HorizontalOptions = LayoutOptions.CenterAndExpand,
						},
					opv,
					new Label {
						Text = "http://oxyplot.org/doc/HelloWpfXaml.html",
						Font = Font.SystemFontOfSize(NamedSize.Small),
						VerticalOptions = LayoutOptions.CenterAndExpand,
						HorizontalOptions = LayoutOptions.CenterAndExpand,
					},
				}
			};
		}
        public BasicSquareWave()
        {
            this.Title = "Gráfico";
            //this.Icon = "Icon.png";

            PlotModel myModel = new PlotModel("Square wave");
            var       ls      = new LineSeries("sin(x)+sin(3x)/3+sin(5x)/5+...");
            int       n       = 10;

            for (double x = -10; x < 10; x += 0.0001)
            {
                double y = 0;
                for (int i = 0; i < n; i++)
                {
                    int j = i * 2 + 1;
                    y += Math.Sin(j * x) / j;
                }
                ls.Points.Add(new DataPoint(x, y));
            }
            myModel.Series.Add(ls);
            myModel.Axes.Add(new LinearAxis(AxisPosition.Left, -4, 4));
            myModel.Axes.Add(new LinearAxis(AxisPosition.Bottom));

            var opv = new OxyPlotView {
                WidthRequest = 300, HeightRequest = 300
            };

            opv.Model = myModel;

            this.Content = new StackLayout
            {
                Spacing         = 20,
                Padding         = 10,
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    opv
                }
            };
        }
		public BasicSquareWave ()
		{
			this.Title = "Gráfico";
			//this.Icon = "Icon.png";

			PlotModel myModel = new PlotModel("Square wave");
			var ls = new LineSeries("sin(x)+sin(3x)/3+sin(5x)/5+...");
			int n = 10;
			for (double x = -10; x < 10; x += 0.0001)
			{
				double y = 0;
				for (int i = 0; i < n; i++)
				{
					int j = i * 2 + 1;
					y += Math.Sin(j * x) / j;
				}
				ls.Points.Add(new DataPoint(x, y));
			}
			myModel.Series.Add(ls);
			myModel.Axes.Add(new LinearAxis(AxisPosition.Left, -4, 4));
			myModel.Axes.Add(new LinearAxis(AxisPosition.Bottom));

			var opv = new OxyPlotView {WidthRequest = 300, HeightRequest = 300};
			opv.Model = myModel;

			this.Content = new StackLayout
			{
				Spacing = 20,
				Padding = 10,
				VerticalOptions = LayoutOptions.Center,
				Children =
				{
					opv
				}
			};
		}
		public GraphViewPage (ExampleInfo exampleInfo)
		{
			var opv = new OxyPlotView {
				WidthRequest = 300,
				HeightRequest = 300,
			};
			opv.Model = exampleInfo.PlotModel;

			var label = new Label {
				Text = "Category: " + exampleInfo.Category,
				VerticalOptions = LayoutOptions.CenterAndExpand,
				HorizontalOptions = LayoutOptions.CenterAndExpand,
			};

			bool GameOfLife = exampleInfo.Title.Contains ("Conway");
			if (!GameOfLife) {
				Content = new StackLayout {
					BackgroundColor = Color.White,
					Orientation = StackOrientation.Vertical,
					VerticalOptions = LayoutOptions.StartAndExpand,
					Children = {
						opv,
						label
					}
				};
			} else {

				var stepButton = new Button {
					Text = "step"
				};
				stepButton.Clicked += (sender, e) => {
					var ea = new OxyMouseDownEventArgs ();
					ea.ChangedButton = OxyMouseButton.Left;
					ea.Position = new ScreenPoint (150, 150);
					opv.Model.HandleMouseDown (this, ea);
					opv.InvalidateDisplay ();
				};


				var startButton = new Button {
					Text = "run"
				};
				startButton.Clicked += (sender, e) => {
					if (!keepRunning) {
						keepRunning = true;
						Device.StartTimer (new TimeSpan (0, 0, 0, 0, 200), () => {
							var ea = new OxyMouseDownEventArgs ();
							ea.ChangedButton = OxyMouseButton.Left;
							ea.Position = new ScreenPoint (150, 150);
							opv.Model.HandleMouseDown (this, ea);
							Device.BeginInvokeOnMainThread(() => {
								opv.InvalidateDisplay ();
							});
							return keepRunning;
						});
					}
				};
				var stopButton = new Button {
					Text = "stop"
				};
				stopButton.Clicked += (sender, e) => {
					keepRunning = false;
				};

				Content = new StackLayout {
					Orientation = StackOrientation.Vertical,
					VerticalOptions = LayoutOptions.FillAndExpand,
					Children = {
						opv,
						label,
						new StackLayout {
							HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions = LayoutOptions.StartAndExpand,
							Orientation = StackOrientation.Horizontal,
                            Children = { stepButton, startButton, stopButton }
						}

					}
				};
			}
		}
		public WeatherObservationPage ()
		{
			var weatherSeries = new LineSeries ();

			var m = new PlotModel ("Weather");

			var magnitudeAxis = new OxyPlot.Axes.LinearAxis ();
			magnitudeAxis.Minimum = 0;
			magnitudeAxis.Maximum = 40;
			magnitudeAxis.Title = "Temperature";
			m.Axes.Add (magnitudeAxis);

			var dateAxis = new OxyPlot.Axes.CategoryAxis ();
			dateAxis.Labels.Add("Station");
			m.Axes.Add (dateAxis);

			weatherSeries.ItemsSource = new List<DataPoint> (); // empty to start
			m.Series.Add (weatherSeries);

			var opv = new OxyPlotView {
				WidthRequest = 300, HeightRequest = 300,
				BackgroundColor = Color.Aqua
			};
			opv.Model = m;

			Insights.Track ("SHOWGRAPH");


			var l = new Label {
				Text = "Hello, Oxyplot!",
				VerticalOptions = LayoutOptions.CenterAndExpand,
				HorizontalOptions = LayoutOptions.CenterAndExpand,
			};
			var b = new Button { Text = "Get Weather Data" };
			b.Clicked += async (sender, e) => {
				var sv = new GeoNamesWebService();
				var we = await sv.GetWeatherObservationsAsync();
				Xamarin.Forms.Device.BeginInvokeOnMainThread( () => {
					Debug.WriteLine("found " + we.Length + " weather observations");
					l.Text = we.Length + " weather observations";

					var eqlist = new List<WeatherObservation>(we);
//					eqlist.Sort((x, y) => string.Compare(x.datetime, y.datetime));


					var columSeries = new ColumnSeries();


					foreach (var eq in eqlist) {
						double t = 0.0;
						Double.TryParse(eq.temperature, out t);
						columSeries.Items.Add(new ColumnItem(t, 0));
						//pts.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Parse(eq.datetime)), Double.Parse(eq.temperature)));
					}
					opv.Model.Series.Clear();
					opv.Model.Series.Add(columSeries);

					Device.BeginInvokeOnMainThread(() => {
						opv.InvalidateDisplay ();
					});
				});
			};


			Padding = new Thickness (0, 20, 0, 0);
			Content = new StackLayout {
				Children = {
					opv,
					b,
					l
				}
			};
		}
        public EarthquakePage()
        {
            var earthquakeSeries = new LineSeries();

            var m = new PlotModel("Earthquakes");

            var magnitudeAxis = new OxyPlot.Axes.LinearAxis();

            magnitudeAxis.Minimum = 0;
            magnitudeAxis.Maximum = 10;
            m.Axes.Add(magnitudeAxis);

            var dateAxis = new OxyPlot.Axes.DateTimeAxis();

            dateAxis.IntervalType = OxyPlot.Axes.DateTimeIntervalType.Days;
            dateAxis.StringFormat = "MMMM-yy";
            m.Axes.Add(dateAxis);

            earthquakeSeries.ItemsSource = new List <DataPoint> ();            // empty to start
            m.Series.Add(earthquakeSeries);

            var opv = new OxyPlotView {
                WidthRequest    = 300, HeightRequest = 300,
                BackgroundColor = Color.Aqua
            };

            opv.Model = m;

            Insights.Track("SHOWGRAPH");


            var l = new Label {
                Text              = "Hello, Oxyplot!",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            var b = new Button {
                Text = "Get Earthquake Data"
            };

            b.Clicked += async(sender, e) => {
                var sv = new GeoNamesWebService();
                var es = await sv.GetEarthquakesAsync();

                Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                    Debug.WriteLine("found " + es.Length + " earthquakes");
                    l.Text = es.Length + " earthquakes";

                    var eqlist = new List <Earthquake>(es);
                    eqlist.Sort((x, y) => string.Compare(x.datetime, y.datetime));

                    var pts = new List <DataPoint>();
                    foreach (var eq in eqlist)
                    {
                        pts.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Parse(eq.datetime)), eq.magnitude));
                    }

                    earthquakeSeries.ItemsSource = pts;
                    earthquakeSeries.XAxis.CoerceActualMaxMin();

                    Device.BeginInvokeOnMainThread(() => {
                        opv.InvalidateDisplay();
                    });
                });
            };


            Padding = new Thickness(0, 20, 0, 0);
            Content = new StackLayout {
                Children =
                {
                    opv,
                    b,
                    l
                }
            };
        }
        public GraphViewPage(ExampleInfo exampleInfo)
        {
            var opv = new OxyPlotView {
                WidthRequest  = 300,
                HeightRequest = 300,
            };

            opv.Model = exampleInfo.PlotModel;

            var label = new Label {
                Text              = "Category: " + exampleInfo.Category,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };

            bool GameOfLife = exampleInfo.Title.Contains("Conway");

            if (!GameOfLife)
            {
                Content = new StackLayout {
                    BackgroundColor = Color.White,
                    Orientation     = StackOrientation.Vertical,
                    VerticalOptions = LayoutOptions.StartAndExpand,
                    Children        =
                    {
                        opv,
                        label
                    }
                };
            }
            else
            {
                var stepButton = new Button {
                    Text = "step"
                };
                stepButton.Clicked += (sender, e) => {
                    var ea = new OxyMouseDownEventArgs();
                    ea.ChangedButton = OxyMouseButton.Left;
                    ea.Position      = new ScreenPoint(150, 150);
                    opv.Model.HandleMouseDown(this, ea);
                    opv.InvalidateDisplay();
                };


                var startButton = new Button {
                    Text = "run"
                };
                startButton.Clicked += (sender, e) => {
                    if (!keepRunning)
                    {
                        keepRunning = true;
                        Device.StartTimer(new TimeSpan(0, 0, 0, 0, 200), () => {
                            var ea           = new OxyMouseDownEventArgs();
                            ea.ChangedButton = OxyMouseButton.Left;
                            ea.Position      = new ScreenPoint(150, 150);
                            opv.Model.HandleMouseDown(this, ea);
                            Device.BeginInvokeOnMainThread(() => {
                                opv.InvalidateDisplay();
                            });
                            return(keepRunning);
                        });
                    }
                };
                var stopButton = new Button {
                    Text = "stop"
                };
                stopButton.Clicked += (sender, e) => {
                    keepRunning = false;
                };

                Content = new StackLayout {
                    Orientation     = StackOrientation.Vertical,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Children        =
                    {
                        opv,
                        label,
                        new StackLayout {
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.StartAndExpand,
                            Orientation       = StackOrientation.Horizontal,
                            Children          = { stepButton, startButton, stopButton }
                        }
                    }
                };
            }
        }
		public EarthquakePage ()
		{
			var earthquakeSeries = new LineSeries ();

			var m = new PlotModel ("Earthquakes");

			var magnitudeAxis = new OxyPlot.Axes.LinearAxis ();
			magnitudeAxis.Minimum = 0;
			magnitudeAxis.Maximum = 10;
			m.Axes.Add (magnitudeAxis);

			var dateAxis = new OxyPlot.Axes.DateTimeAxis ();
			dateAxis.IntervalType = OxyPlot.Axes.DateTimeIntervalType.Days;
			dateAxis.StringFormat = "MMMM-yy";
			m.Axes.Add (dateAxis);

			earthquakeSeries.ItemsSource = new List<DataPoint> (); // empty to start
			m.Series.Add (earthquakeSeries);

			var opv = new OxyPlotView {
				WidthRequest = 300, HeightRequest = 300,
				BackgroundColor = Color.Aqua
			};
			opv.Model = m;

			Insights.Track ("SHOWGRAPH");


			var l = new Label {
				Text = "Hello, Oxyplot!",
				VerticalOptions = LayoutOptions.CenterAndExpand,
				HorizontalOptions = LayoutOptions.CenterAndExpand,
			};
			var b = new Button { Text = "Get Earthquake Data" };
			b.Clicked += async (sender, e) => {
				var sv = new GeoNamesWebService();
				var es = await sv.GetEarthquakesAsync();
				Xamarin.Forms.Device.BeginInvokeOnMainThread( () => {
					Debug.WriteLine("found " + es.Length + " earthquakes");
					l.Text = es.Length + " earthquakes";

					var eqlist = new List<Earthquake>(es);
					eqlist.Sort((x, y) => string.Compare(x.datetime, y.datetime));

					var pts = new List<DataPoint>();
					foreach (var eq in eqlist) {
						pts.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Parse(eq.datetime)), eq.magnitude));
					}

					earthquakeSeries.ItemsSource = pts;
					earthquakeSeries.XAxis.CoerceActualMaxMin();

					Device.BeginInvokeOnMainThread(() => {
						opv.InvalidateDisplay ();
					});
				});
			};


			Padding = new Thickness (0, 20, 0, 0);
			Content = new StackLayout {
				Children = {
					opv,
					b,
					l
				}
			};
		}
        public WeatherObservationPage()
        {
            var weatherSeries = new LineSeries();

            var m = new PlotModel("Weather");

            var magnitudeAxis = new OxyPlot.Axes.LinearAxis();

            magnitudeAxis.Minimum = 0;
            magnitudeAxis.Maximum = 40;
            magnitudeAxis.Title   = "Temperature";
            m.Axes.Add(magnitudeAxis);

            var dateAxis = new OxyPlot.Axes.CategoryAxis();

            dateAxis.Labels.Add("Station");
            m.Axes.Add(dateAxis);

            weatherSeries.ItemsSource = new List <DataPoint> ();            // empty to start
            m.Series.Add(weatherSeries);

            var opv = new OxyPlotView {
                WidthRequest    = 300, HeightRequest = 300,
                BackgroundColor = Color.Aqua
            };

            opv.Model = m;

            Insights.Track("SHOWGRAPH");


            var l = new Label {
                Text              = "Hello, Oxyplot!",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            var b = new Button {
                Text = "Get Weather Data"
            };

            b.Clicked += async(sender, e) => {
                var sv = new GeoNamesWebService();
                var we = await sv.GetWeatherObservationsAsync();

                Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                    Debug.WriteLine("found " + we.Length + " weather observations");
                    l.Text = we.Length + " weather observations";

                    var eqlist = new List <WeatherObservation>(we);
//					eqlist.Sort((x, y) => string.Compare(x.datetime, y.datetime));


                    var columSeries = new ColumnSeries();


                    foreach (var eq in eqlist)
                    {
                        double t = 0.0;
                        Double.TryParse(eq.temperature, out t);
                        columSeries.Items.Add(new ColumnItem(t, 0));
                        //pts.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Parse(eq.datetime)), Double.Parse(eq.temperature)));
                    }
                    opv.Model.Series.Clear();
                    opv.Model.Series.Add(columSeries);

                    Device.BeginInvokeOnMainThread(() => {
                        opv.InvalidateDisplay();
                    });
                });
            };


            Padding = new Thickness(0, 20, 0, 0);
            Content = new StackLayout {
                Children =
                {
                    opv,
                    b,
                    l
                }
            };
        }