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