Xamarin chart the development of Basic Course (4) OxyPlot framework
FIG OxyPlotAndroidDemo line drawn XamaminAndroid
[Example 1-1: OxyPlotAndroidDemo] FIG line drawn in the following. Specific steps are as follows:
(1) Open Xamarin.Android project.
(2) adding to OxyPlot.Xamarin.Android assembly incorporated in the project.
(3) open activity_main.axml file, use PlotView layout. code show as below:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <OxyPlot.Xamarin.Android.PlotView android:id="@+id/plot_view" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
(4) Open file MainActivity.cs achieve the remaining steps in this document, i.e., charting and display mode is set. code show as below:
using Android.App; using Android.OS; using Android.Support.V7.App; using Android.Runtime; using Android.Widget; using OxyPlot.Xamarin.Android; using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; namespace OxyPlotAndroidDemo { [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)] public class MainActivity : AppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView (Resource.Layout.activity_main); PlotView View findViewById = <PlotView> (Resource.Id.plot_view); view.Model CreatePlotModel = (); // set the display mode } // graphed Private PlotModel CreatePlotModel () { // Create a chart pattern var plotModel new new PlotModel = { the Title = "OxyPLOT Demo" }; // add the axis plotModel.Axes.Add (new new AxisPosition.Bottom the Position = {} the LinearAxis); plotModel.Axes.Add (new new the LinearAxis the Position = { AxisPosition.Left, Maximum = 10, Minimum = 0}); //创建数据列 var series1 = new LineSeries { Title= "Data", MarkerType = MarkerType.Circle, MarkerSize = 4, MarkerStroke = OxyColors.White }; //添加数据点 series1.Points.Add(new DataPoint(0.0, 6.0)); series1.Points.Add(new DataPoint(1.4, 2.1)); series1.Points.Add(new DataPoint(2.0, 4.2)); series1.Points.Add(new DataPoint(3.3, 2.3)); series1.Points.Add(new DataPoint(4.7, 7.4)); series1.Points.Add(new DataPoint(6.0, 6.2)); series1.Points.Add (new new the DataPoint (8.9, 8.9)); // add data columns plotModel.Series.Add (of Series1); return plotModel; } } }
Running the program, the graph shown in Figure 1.1.
FIG Platform 1.1 Xamarin.Android diagram effect