How to use OxyPlot Framework in Xamarin Chart Development
This article mainly shows you the "Xamarin chart development in how to use the OxyPlot framework", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "Xamarin chart development in the OxyPlot framework how to use" this article.
Drawing Line Graph OxyPlotAndroidDemo in XamaminAndroid
[example 1-1:OxyPlotAndroidDemo] the drawing of the line graph is realized below. The specific steps are as follows:
(1) Open the Xamarin.Android project.
(2) add OxyPlot.Xamarin.Android components to the introduction in the project.
(3) Open the activity_main.axml file and use PlotView for layout. The code is as follows:
(4) Open the MainActivity.cs file and implement the remaining steps in this file, that is, drawing the chart and setting the display mode. The code is as follows:
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 (Resource.Id.plot_view); view.Model = CreatePlotModel () / / set display mode} / / draw a chart private PlotModel CreatePlotModel () {/ / create a chart mode var plotModel = new PlotModel {Title = "OxyPlot Demo"} / / add axis plotModel.Axes.Add (new LinearAxis {Position = AxisPosition.Bottom}); plotModel.Axes.Add (new LinearAxis {Position = AxisPosition.Left, Maximum = 10, Minimum = 0}) / / create data columns var series1 = new LineSeries {Title= "Data", MarkerType = MarkerType.Circle, MarkerSize = 4, MarkerStroke = OxyColors.White}; / / add data point 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 DataPoint (8.9,8.9)); / / add data column plotModel.Series.Add (series1); return plotModel;}}
Run the program, and the chart shown in figure 1.1 is shown.
Figure 1.1 Graph effect of the Xamarin.Android platform
These are all the contents of this article entitled "how to use the OxyPlot Framework in Xamarin Chart Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!