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

            {

                //创建并将主页面的内容设置为PlotView

                Content = 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 = , Minimum =  });

            //创建数据列

            var series1 = new LineSeries

            {

                Title = "Data",

                MarkerType = MarkerType.Circle,

                MarkerSize = ,

                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图表开发基础教程(9)OxyPlot框架

    Xamarin图表开发基础教程(9)OxyPlot框架 OxyPlot组件构成 OxyPlot组件主要由两个类构成,分别为PlotView和PlotModel.这两个类我们在上文中也使用到了.本节将讲 ...

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

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

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

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

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

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

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

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

随机推荐

  1. H3C Short GI

  2. Linux指令(时间日期类)

    date指令-显示当前日期 基本语法: 1)date (功能描述:显示当前时间) 2)date +%Y (功能描述:显示当前年份) 3)date +%m (功能描述:显示当前月份) 4)date +% ...

  3. 定时任务模块——APScheduler

    一.概念: python定时任务框架,基于日期,固定时间间隔,crontab类型的任务,并且可以持久化任务,并能以deamon守护方式运行任务 二.简介: 安装:pip install apsched ...

  4. 决策树算法原理--good blog

    转载于:http://www.cnblogs.com/pinard/p/6050306.html (楼主总结的很好,就拿来主义了,不顾以后还是多像楼主学习) 决策树算法在机器学习中算是很经典的一个算法 ...

  5. django migrate报错:1005 - Can't create table xxx (errno: 150 "Foreign key constraint is incorrectly formed")

    自从mysql升级,以及使用mariaDB以来,很多不曾更新django中model的外键, 今天,按以前的思路写完外键之后, migrate命令报错: 1005 - Can't create tab ...

  6. 如果在使用谷歌的gson的时候,在返回时间类型的数据的时候,

    可能会出现在long类型的时间后面多3个0 如下图所示 可以自己创建一个json序列化的类 public class Date2LongSerializer extends JsonSerialize ...

  7. 对于模块加载:ES6、CommonJS、AMD、CMD的区别

    运行和编译的概念 编译包括编译和链接两步. 编译,把源代码翻译成机器能识别的代码或者某个中间状态的语言. 比如java只有JVM识别的字节码,C#中只有CLR能识别的MSIL.还简单的作一些比如检查有 ...

  8. forword动作

    forword动作   服务器内部跳转指令 语法为: <jsp:forword page = "目标页面"> 等同于:request.getRequestDispatc ...

  9. 小a的学期 (组合数取模模板)

    题目描述 小a是一个健忘的人,由于他经常忘记做作业,因此老师对他很恼火. 小a马上就要开学了,他学期一共2n 天,对于第i天,他有可能写了作业,也可能没写作业,不过他自己心里还有点B数,因此他会写恰好 ...

  10. EventWaitHandle 第一课

    本篇通过一个列子使用EventWaitHandle实现两个线程的同步.请参看下面的列子. using System; using System.Collections.Generic; using S ...