WPF中使用LiveCharts绘制散点图

一、背景

       这里的代码使用MVVM模式进行编写

二、Model

public class DataPoint
    {
        public double X { get; set; }
        public double Y { get; set; }
    }

三、ViewModel

public class ScatterChartViewModel
    {


        public SeriesCollection Series { get; set; }


        public ScatterChartViewModel()
        {
            //初始化数据
            var dataPoints = new List<DataPoint>
            {
                new DataPoint { X= 1, Y= 10 },
                new DataPoint { X= 2, Y= 20 },
                new DataPoint { X= 3, Y= 15 },
            };


            Series = new SeriesCollection()
            {
                new ScatterSeries
                {
                    Title = "Data",
                    Values = new ChartValues<ObservablePoint>(posPoints.Select(dp => new ObservablePoint(dp.X, dp.Y)))
                }
            };        
        }  

    }

四、View

<Window x:Class="DisplayData.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DisplayData.Views"
        mc:Ignorable="d"
        xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        Title="Data" Height="900" Width="1200" WindowStartupLocation="CenterScreen">
    <Grid>          
            <lvc:CartesianChart Series="{Binding Series}" BorderBrush="#7ADA95" BorderThickness="1">
            </lvc:CartesianChart>       
    </Grid>
</Window>
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new ScatterChartViewModel();
        }
    }

相关推荐

  1. WPF使用LiveCharts绘制

    2024-03-14 19:50:02       39 阅读
  2. python绘制

    2024-03-14 19:50:02       35 阅读
  3. matlab绘制

    2024-03-14 19:50:02       36 阅读
  4. python绘制三维

    2024-03-14 19:50:02       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-14 19:50:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-14 19:50:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-14 19:50:02       82 阅读
  4. Python语言-面向对象

    2024-03-14 19:50:02       91 阅读

热门阅读

  1. SQLite语句

    2024-03-14 19:50:02       40 阅读
  2. mysql订单表设计

    2024-03-14 19:50:02       35 阅读
  3. vector与list的区别与应用?

    2024-03-14 19:50:02       46 阅读
  4. 依赖注入与控制反转:优化Go语言REST API客户端

    2024-03-14 19:50:02       39 阅读
  5. 探索信号处理:低通滤波器的原理与应用

    2024-03-14 19:50:02       36 阅读
  6. ts中高阶类型的理解

    2024-03-14 19:50:02       38 阅读
  7. 最少刷题数

    2024-03-14 19:50:02       42 阅读
  8. 工作随记:oracle重建一张1T数据量的大表

    2024-03-14 19:50:02       47 阅读
  9. c#计算闰年

    2024-03-14 19:50:02       35 阅读
  10. 基于ElasticSearch的海量AIS数据存储方法

    2024-03-14 19:50:02       44 阅读
  11. 【Python】-闲聊:如何系统的自学Ptyhon

    2024-03-14 19:50:02       45 阅读
  12. PHP序列化基础知识储备

    2024-03-14 19:50:02       38 阅读
  13. Oracle——用户、角色、权限的创建、删除、修改

    2024-03-14 19:50:02       41 阅读