這篇文章主要為大家展示了“Xamarin圖表開發中OxyPlot框架怎么用”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Xamarin圖表開發中OxyPlot框架怎么用”這篇文章吧。
【示例1-1:OxyPlotAndroidDemo】下面實現線圖的繪制。具體的操作步驟如下:
(1)打開Xamarin.Android項目。
(2)將OxyPlot.Xamarin.Android組件添加到項目中的引入中。
(3)打開activity_main.axml文件,使用PlotView進行布局。代碼如下:
<?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)打開MainActivity.cs文件,在此文件中實現剩余的步驟,即繪制圖表并設置顯示模式。代碼如下:
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(); //設置顯示模式 } //繪制圖表 private PlotModel CreatePlotModel() { //創建圖表模式 var plotModel = new PlotModel { Title = "OxyPlot Demo" }; //添加坐標軸 plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { 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 DataPoint(8.9, 8.9)); //添加數據列 plotModel.Series.Add(series1); return plotModel; } } }
運行程序,顯示的圖表如圖1.1所示。
圖1.1 Xamarin.Android平臺的線圖效果
以上是“Xamarin圖表開發中OxyPlot框架怎么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。