private void scalingXY() { DataPoint[] points = new DataPoint[100]; for (int i = 0; i < points.Length; i++) { points[i] = new DataPoint(i, Math.Sin(i * 0.5) * 20 * (Math.Random() * 10 + 1)); } LineGraphSeries series = new LineGraphSeries(points); // set manual X bounds graphView.Viewport.YAxisBoundsManual = true; graphView.Viewport.SetMinY(-150); graphView.Viewport.SetMaxY(150); graphView.Viewport.XAxisBoundsManual = true; graphView.Viewport.SetMinX(4); graphView.Viewport.SetMaxX(80); // enable scaling graphView.Viewport.Scalable = true; graphView.Viewport.SetScalableY(true); series.Title = "Random Curve"; graphView.AddSeries(series); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); _graph = FindViewById <GraphView> (Resource.Id.graph); var points = StepModel.Mockup ().Select ( (x, i) => new DataPoint ( new Java.Util.Date (x.Date.Ticks), x.Steps) ).ToArray (); BarGraphSeries series = new BarGraphSeries (points); series.Spacing = 20; series.DrawValuesOnTop = true; series.ValuesOnTopColor = (int)Color.Yellow; series.Color = (int)Color.Yellow; _graph.GridLabelRenderer.LabelFormatter = new DateLabelFormat (); _graph.GridLabelRenderer.NumHorizontalLabels = 5; _graph.AddSeries (series); _graph.Viewport.SetMaxY (points.Max (x => x.GetY()) + 100); _graph.Viewport.SetMinY (0); _graph.Viewport.YAxisBoundsManual = true; double aDay = 24 * 60 * 60 * 1000; _graph.Viewport.SetMaxX (points.Max (x => x.GetX()) + aDay); _graph.Viewport.SetMinX (points.Min (x => x.GetX()) - aDay); _graph.Viewport.XAxisBoundsManual = true; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.GraphViewLayout); ActionBar.Hide(); //.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape; this.RequestedOrientation = ScreenOrientation.SensorLandscape; GraphView graph = FindViewById <GraphView>(Resource.Id.graph); // first series is a line DataPoint[] points = new DataPoint[100]; Random rand = new Random(); for (int i = 0; i < points.Length; i++) { points[i] = new DataPoint(i, Math.Sin(i * 0.5) * 20 * (rand.NextDouble() * 10 + 1)); } LineGraphSeries series = new LineGraphSeries(points); //series.Color = Resource.Color.colorPrimary; //series.Color = Resource.Color.testColor; DataPoint[] points1 = new DataPoint[200]; Random rand1 = new Random(); for (int i = 0; i < points1.Length; i++) { points1[i] = new DataPoint(i, Math.Sin(i * 0.5) * 10 * (rand1.NextDouble() * 2 + 1)); } LineGraphSeries series1 = new LineGraphSeries(points1); series1.Color = Resource.Color.launcher_background; //graph.Viewport.BackgroundColor = Resource.Color.abc_background_cache_hint_selector_material_dark; // set manual X graph.Viewport.YAxisBoundsManual = true; graph.Viewport.SetMinY(-150); graph.Viewport.SetMaxY(150); graph.Viewport.XAxisBoundsManual = true; graph.Viewport.SetMinX(4); graph.Viewport.SetMaxX(80); // enable scaling graph.Viewport.Scalable = true; graph.Viewport.SetScalableY(true); series.Title = "Random Curve"; //series.setTitle("Random Curve 1"); series.Color = unchecked ((int)0xFF00FF00); series.DrawDataPoints = true; //series.DataPointsRadius = 10; //series.setDrawDataPoints(true); //series.setDataPointsRadius(10); //series.setThickness(8); series1.Title = "Random1 Curve"; series1.Color = unchecked ((int)0xFFFF0000); series1.DrawDataPoints = true; graph.AddSeries(series); graph.AddSeries(series1); graph.LegendRenderer.Visible = true; graph.LegendRenderer.Align = LegendRenderer.LegendAlign.Top; }