温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Xamarin图表开发中OxyPlot框架怎么用

发布时间:2021-12-21 11:20:26 来源:亿速云 阅读:170 作者:小新 栏目:移动开发

这篇文章主要为大家展示了“Xamarin图表开发中OxyPlot框架怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Xamarin图表开发中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所示。

Xamarin图表开发中OxyPlot框架怎么用

图1.1  Xamarin.Android平台的线图效果

以上是“Xamarin图表开发中OxyPlot框架怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI