Avalonia学习(十五)-OxyPlot

今天开始继续Avalonia练习。展示一些样例,尤其是第三方库的使用。

本节:OxyPlot

1.引入OxyPlot.Avalonia

2.项目引入

在Main方法里增加OxyPlotModule.EnsureLoaded()方法调用。

public static void Main(string[] args)
{
    OxyPlotModule.EnsureLoaded();
    AppBuilder.Configure()
        .UsePlatformDetect()
        .StartWithClassicDesktopLifetime(args);
}

在App.xaml文件中增加样式引用。


             

    
        
    
  
    
        
      
     
    

前台代码



    
        
        
    
      
    


后台代码

using OxyPlot;
using OxyPlot.Series;
using System.Collections.Generic;

namespace OxyPlotAvalonia.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
#pragma warning disable CA1822 // Mark members as static
        public string Greeting => "Welcome to Avalonia!";
#pragma warning restore CA1822 // Mark members as static
        public PlotModel Model { get; private set; }
        public MainWindowViewModel()
        {

         //   OxyPlot.Avalonia.PlotView plotView=new OxyPlot.Avalonia.PlotView();
         //   plotView.Model = Model;
            // Create the plot model
            var tmp = new PlotModel { Title = "Simple example", Subtitle = "using OxyPlot" };

           // OxyPlot.Series.Series series=new  
            // Create two line series (markers are hidden by default)
          
            var series1 = new LineSeries { Title = "Series 1", MarkerType = MarkerType.Circle };
            List points = new List();
            points.Add(new DataPoint(0, 0));
            points.Add(new DataPoint(10, 18));
            points.Add(new DataPoint(20, 12));
            points.Add(new DataPoint(30, 8));
            points.Add(new DataPoint(40, 15));
            series1.ItemsSource = points;

            var series2 = new LineSeries { Title = "Series 2", MarkerType = MarkerType.Square };
            List points1 = new List();
            points.Add(new DataPoint(0, 0));
            points.Add(new DataPoint(10, 18));
            points.Add(new DataPoint(20, 12));
            points.Add(new DataPoint(30, 8));
            points.Add(new DataPoint(40, 15));
            points1.Add(new DataPoint(0, 4));
            points1.Add(new DataPoint(10, 12));
            points1.Add(new DataPoint(20, 16));
            points1.Add(new DataPoint(30, 25));
            points1.Add(new DataPoint(40, 5));
         
            // Add the series to the plot model
            // tmp.Series.Add(series1);
            // tmp.Series.Add(series2);
            tmp.Series.Add(series1);
            this.Model = tmp;
        }
    }
}

运行效果

Avalonia学习(十五)-OxyPlot_第1张图片

经过测试,最新版Avalonia11.0.6会报错,Oxyplot.Avalonia没有对应更新,你要直接用最新Avalonia,可以引入Oxyplot.AvaloniaCore包测试。

你可能感兴趣的:(学习,Avalonia)