Xamarin图表开发基础教程(8)OxyPlot框架

【示例OxyPlotFormsDemo】在Xamarin.Forms中实现线图的显示。

(1)打开Xamarin.Forms项目。

(2)将OxyPlot.Xamarin.Forms组件添加到各个子项目中的引入中。

(3)打开OxyPlotFormsDemo.Android子项目的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)打开OxyPlotFormsDemo.iOS子项目的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)打开App.xaml.cs文件,完成剩余的步骤,即创建PlotView视图、绘制图表、设置显示模式等。代码如下:

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{//创建并将主页面的内容设置为PlotViewContent = new PlotView{Model = CreatePlotModel(),VerticalOptions = LayoutOptions.Fill,HorizontalOptions = LayoutOptions.Fill,}};}//绘制图表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.3所示的效果。

图1.3  Android的效果与 iOS的效果

Xamarin图表开发基础教程(8)OxyPlot框架相关推荐

  1. Xamarin图表开发基础教程(13)OxyPlot框架支持的其它图表

    Xamarin图表开发基础教程(13)OxyPlot框架支持的其它图表 除了以上提到的图表外,OxyPlot组件还包含了6种类型的其它图表,分别为等高线图.箱线图.饼图.热图.散点图和散点误差图,如图 ...

  2. Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型

    Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型 OxyPlot组件中支持5种类型的金融图表,它们分别为销量图.高低图.股票K线图.股票走势图和旧式股票图,如图1.20~1. ...

  3. Xamarin图表开发基础教程(11)OxyPlot框架支持的图表类型

    Xamarin图表开发基础教程(11)OxyPlot框架支持的图表类型 OxyPlot组件中支持7种类型的条型图表,分别为普通条形图.线型条形图.矩形条形图.差值图.龙卷风图.普通柱形图和柱形误差图, ...

  4. Xamarin图表开发基础教程(10)OxyPlot框架支持的图表类型

    Xamarin图表开发基础教程(10)OxyPlot框架支持的图表类型 OxyPlot组件支持26种图表,这些图表按照功能和样式可以分为4大类,分别为线型图表.条型图表.金融图表和其它图表. 线型图表 ...

  5. Xamarin图表开发基础教程(7)OxyPlot框架

    Xamarin图表开发基础教程(7)OxyPlot框架 Xamarin.Forms中使用OxyPlot框架 在Xamarin. Forms平台上实现图表显示需要完成以下的步骤: 1.添加OxyPlot ...

  6. Xamarin图表开发基础教程(6)OxyPlot框架

    Xamarin图表开发基础教程(6)OxyPlot框架 Xamamin iOS中绘制线图OxyPlotiOSDemo [示例OxyPlotiOSDemo]下面将实现线图的显示.具体的操作步骤如下: ( ...

  7. Xamarin图表开发基础教程(5)OxyPlot框架

    Xamarin图表开发基础教程(5)OxyPlot框架 Xamarin.iOS中使用OxyPlot框架 在Xamarin.iOS平台上实现图表显示需要完成以下的步骤: 1.添加OxyPlot.Xama ...

  8. Xamarin图表开发基础教程(4)OxyPlot框架

    Xamarin图表开发基础教程(4)OxyPlot框架 XamaminAndroid中绘制线图OxyPlotAndroidDemo [示例1-1:OxyPlotAndroidDemo]下面实现线图的绘 ...

  9. Xamarin图表开发基础教程(3)OxyPlot框架

    Xamarin图表开发基础教程(3)OxyPlot框架 Xamarin.Android中使用OxyPlot框架 在Xamarin.Android平台上实现图表显示需要完成以下的步骤: 1.添加OxyP ...

最新文章

  1. 禅修笔记——硅谷最受欢迎的情商课
  2. 用sk-learn的pipline的时候,现:TypeError: ‘Pipeline‘ object is not subscriptable
  3. IDEA的查询引用、调用关系图的功能
  4. Win10怎么设置虚拟内存?
  5. Linux系统编程之进程控制(进程创建,fork函数,进程中止,进程等待,程序替换)
  6. java响应很慢排插_服务响应时间慢:Java SecureRandom和/ dev / random - java
  7. 认识零信任安全网络架构
  8. iPhone上传文件到ftp服务器,将文件上传到iPhone上的FTP服务器
  9. asp.net mvc在Model中控制日期格式
  10. c# 标准正太分布函数_数据处理中0-1规范化和标准化
  11. 如何获得Android手机的软件安装列表
  12. 收费企业邮箱有哪些?哪个收费邮箱最好
  13. Flyme patchrom项目笔记
  14. 饮料自动售货机模拟(小项目)
  15. 免费的跨境浏览器能用吗?目前性价比高的跨境浏览器有哪些?
  16. LR之识别图片验证码
  17. JMeter基础系列:接口响应时间
  18. Vue.js结合Canvas制作二维码和图片的合成(qrcanvas + html2canvas)
  19. 三极管的经典之作,你知道吗?
  20. Cesium学习四:使用entity绘制polygon

热门文章

  1. 多线程实现的二种方式
  2. u-boot移植初步尝试-tiny4412
  3. 台北到淡水版Firefox玩网页游戏黑屏
  4. 关于css的float
  5. tornado 学习笔记15 _ServerRequestAdapter分析
  6. 移动端页面输入法挡住input输入框的解决方法
  7. Win7无法安装程序提示Installer integrity check has failed的解决方法
  8. java异常体系结构详解
  9. 超级详细的解决方法 (CentOS7) :永久修改 mysql read-only 问题 could not retrieve transation read-only status server
  10. 使用AngularJS上传文件