Xamarin图表开发基础教程(8)OxyPlot框架
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框架的更多相关文章
- Xamarin图表开发基础教程(13)OxyPlot框架支持的其它图表
Xamarin图表开发基础教程(13)OxyPlot框架支持的其它图表 除了以上提到的图表外,OxyPlot组件还包含了6种类型的其它图表,分别为等高线图.箱线图.饼图.热图.散点图和散点误差图,如图 ...
- Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型
Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型 OxyPlot组件中支持5种类型的金融图表,它们分别为销量图.高低图.股票K线图.股票走势图和旧式股票图,如图1.20~1. ...
- Xamarin图表开发基础教程(11)OxyPlot框架支持的图表类型
Xamarin图表开发基础教程(11)OxyPlot框架支持的图表类型 OxyPlot组件中支持7种类型的条型图表,分别为普通条形图.线型条形图.矩形条形图.差值图.龙卷风图.普通柱形图和柱形误差图, ...
- Xamarin图表开发基础教程(10)OxyPlot框架支持的图表类型
Xamarin图表开发基础教程(10)OxyPlot框架支持的图表类型 OxyPlot组件支持26种图表,这些图表按照功能和样式可以分为4大类,分别为线型图表.条型图表.金融图表和其它图表. 线型图表 ...
- Xamarin图表开发基础教程(9)OxyPlot框架
Xamarin图表开发基础教程(9)OxyPlot框架 OxyPlot组件构成 OxyPlot组件主要由两个类构成,分别为PlotView和PlotModel.这两个类我们在上文中也使用到了.本节将讲 ...
- Xamarin图表开发基础教程(7)OxyPlot框架
Xamarin图表开发基础教程(7)OxyPlot框架 Xamarin.Forms中使用OxyPlot框架 在Xamarin. Forms平台上实现图表显示需要完成以下的步骤: 1.添加OxyPlot ...
- Xamarin图表开发基础教程(6)OxyPlot框架
Xamarin图表开发基础教程(6)OxyPlot框架 Xamamin iOS中绘制线图OxyPlotiOSDemo [示例OxyPlotiOSDemo]下面将实现线图的显示.具体的操作步骤如下: ( ...
- Xamarin图表开发基础教程(5)OxyPlot框架
Xamarin图表开发基础教程(5)OxyPlot框架 Xamarin.iOS中使用OxyPlot框架 在Xamarin.iOS平台上实现图表显示需要完成以下的步骤: 1.添加OxyPlot.Xama ...
- Xamarin图表开发基础教程(4)OxyPlot框架
Xamarin图表开发基础教程(4)OxyPlot框架 XamaminAndroid中绘制线图OxyPlotAndroidDemo [示例1-1:OxyPlotAndroidDemo]下面实现线图的绘 ...
随机推荐
- unittest使用
unittest:单元测试框架主要包含四部分: 1.测试固件(test fixture): 定义:包含执行测试前的准备setUP().测试执行完后的清扫工作tearDown() 注意: setUp() ...
- 【Docker】iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8480 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name
启动容器的时候,出现如下错误: Error response / --dport -j DNAT --to-destination ! -i docker0: iptables: No chain/t ...
- Linux命令——blkid
简介 blkid用于查看块设备UUID.Label.挂载.文件系统类型等信息 选项参数 无参数——显示所有已挂载分区信息 查看特定分区 -s:指定输出信息(UUID.TYPE.LABEL.PTTYPE ...
- WebKit应用程序开发的起因
公司的Web管理界面,用起来还可以,但是有一个问题一直无法解决. 在web页面上需要播放视频,由于比较这个功能比较老,不支持web模式播放,只支持CS模式,具体原因及不说了. 于是有了 winform ...
- drf框架(2)
drf框架 """接口: 接口规范: drf的生命周期: 序列化组件: 三大认证:过滤,删选,排序组件 请求,响应,解析,异常 jwt:json web tooken & ...
- 项目Alpha冲刺——集合
作业描述 课程: 软件工程1916|W(福州大学) 作业要求: 项目Alpha冲刺(团队) 团队名称: 火鸡堂 作业目标: 完成项目Alpha冲刺 团队信息 队名:火鸡堂 队员学号 队员姓名 博客地址 ...
- linux下用vim写Python自动缩进的配置
#首先用 find / -name vimrc 找到vimrc文件#一般在 /etc/vimrc#进入vimrc后加入以下命令 set number set autoindent set shiftw ...
- .net 代码调用cmd执行.exe程序,获取控制台输出信息
使用.net core 对老项目升级, .net core 使用TripleDES.Create() 加密众iv字节限制 与 framework中的不同, 新项目还需要兼容老项目版本,还不想通过web ...
- 树上最长不下降链 线段树合并+set
读错题了,然后写了一个树上 LIS,应该是对的吧...... code: #include <bits/stdc++.h> #define N 200005 #define LL long ...
- 2019.12.11 java方法(类似功能、函数)
方法的具体语法格式如下: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2,......){ 执行语句 ……… return 返回值; } class D ...