【示例OxyPlotFormsDemo 】在Xamarin.Forms中實(shí)現(xiàn)線圖的顯示。
成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的松陽(yáng)網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!(1)打開(kāi)Xamarin.Forms項(xiàng)目。
(2)將OxyPlot.Xamarin.Forms組件添加到各個(gè)子項(xiàng)目中的引入中。
(3)打開(kāi)OxyPlotFormsDemo.Android子項(xiàng)目的MainActivity.cs文件,初始化OxyPlot渲染器,代碼如下:
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace OxyPlotFormsDemo.Droid
{
[Activity(Label = "OxyPlotFormsDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();
LoadApplication(new App());
}
}
}
(4)打開(kāi)OxyPlotFormsDemo.iOS子項(xiàng)目的AppDelegate.cs文件,初始化OxyPlot渲染器,代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace OxyPlotFormsDemo.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
OxyPlot.Xamarin.Forms.Platform.iOS.PlotViewRenderer.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
}
(5)打開(kāi)App.xaml.cs文件,完成剩余的步驟,即創(chuàng)建PlotView視圖、繪制圖表、設(shè)置顯示模式等。代碼如下:
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Xamarin.Forms;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace OxyPlotFormsDemo
{
public partial class App : Application
{
public App()
{
MainPage = new ContentPage
{
//創(chuàng)建并將主頁(yè)面的內(nèi)容設(shè)置為PlotView
Content = new PlotView
{
Model = CreatePlotModel(),
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
}
};
}
//繪制圖表
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)行程序,會(huì)看到如圖1.3所示的效果。

圖1.3 Android的效果與 iOS的效果
本文題目:Xamarin圖表開(kāi)發(fā)基礎(chǔ)教程(8)OxyPlot框架-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://www.yijiale78.com/article26/cspscg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航、網(wǎng)站收錄、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
移動(dòng)網(wǎng)站建設(shè)知識(shí)