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

XamaminAndroid中绘制线图OxyPlotAndroidDemo

【示例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图表开发基础教程(4)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图表开发基础教程(8)OxyPlot框架

    Xamarin图表开发基础教程(8)OxyPlot框架 [示例OxyPlotFormsDemo]在Xamarin.Forms中实现线图的显示. (1)打开Xamarin.Forms项目. (2)将Ox ...

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

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

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

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

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

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

随机推荐

  1. node.js 学习一

    Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. 与PHP 相似 都是单进程. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调 ...

  2. gRPC应用C++

    1.  gRPC简述 RPC,远程方法调用,就是像调用本地方法一样调用远程方法. gRPC是Google实现的一种RPC框架,基于HTTP/2标准设计,带来诸如双向流.流控.头部压缩.单 TCP 连接 ...

  3. golang版本管理工具GO111MODULE

    在go1.11版本前,想要对go语言包进行管理,只能依赖第三方库实现,比如Vendor,GoVendor,GoDep,Dep,Glide等等. 1. 开启GO111MODULE 用环境变量 GO111 ...

  4. Linux文本处理三剑客之grep及正则表达式详解

    Linux文本处理三剑客之grep及正则表达式详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Linux文本处理三剑客概述 grep: 全称:"Global se ...

  5. 【Django2.0】python manage.py makemigrations 和 python manage.py migrate的区别

    无论当我们第一次在models.py中创建类对象还是对类中的属性进行修改,我们都会使用python manage.py makemigrations 和 python manage.py migrat ...

  6. 解决 Vue 刷新页面后 store 数据丢失的问题

    原来的状态(页面刷新数据会重置) state: { teamA: '主队' }, mutations: { data_teamA(state, x) { state.teamA = x } },   ...

  7. c++实现按行读取文本文件

    包含头文件fstream既可以读又可以写(我的理解是头文件fstream中包含ifstream和ofstream),可以同时创建ifstream对象和ofstream对象,分别实现读写:也可以直接创建 ...

  8. 使用js对社会信用代码进行正则验证

    注:参考了该博客(https://blog.csdn.net/qq_37142340/article/details/80695187)进行了一些修改,本文验证使用在微信小程序上. 直接贴代码: va ...

  9. Mybatis容易遇到的问题

    1.MyBatis中#和$的区别? 1.使用#的原理是?占位符,而$的原理为直接字符串拼接方式 2.$方式一般使用在写数据库中的固定字段时候才会使用例如表名或者列名(select * from use ...

  10. collections.defaultdict()

    https://www.cnblogs.com/herbert/archive/2013/01/09/2852843.html >>> import collections > ...