c# wpf LiveCharts 绑定 简单试验

1.概要

c# wpf LiveCharts 绑定 简单试验

2.代码

复制代码
<Window x:Class="WpfApp3.Window2"
        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:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        xmlns:local="clr-namespace:WpfApp3"
        mc:Ignorable="d"
        Title="Window2" Height="450" Width="800">
    <Grid>
        <lvc:CartesianChart Series="{Binding Series}" LegendLocation="Bottom"/>
    </Grid>
</Window>

using LiveCharts.Wpf.Charts.Base;
using LiveCharts.Wpf;
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WpfApp3
{
    /// <summary>
    /// Window2.xaml 的交互逻辑
    /// </summary>
    public partial class Window2 : Window
    {
        public Window2()
        {
            InitializeComponent();
            this.DataContext = new HomePgVM();
        }
        
    }
    public class HomePgVM : NotifyPropertyBase
    {

        public SeriesCollection Series { get; set; }

        public HomePgVM()
        {
            Series = new SeriesCollection()
            {
                new LineSeries
                {
                    Title="充值",
                    DataLabels=true,
                    Values = new ChartValues<double> { 23, 15, 47, 64,30,32,21 },
                    //Fill=new SolidColorBrush(Colors.LightGreen),
                },
            };
        }

    }
    /// <summary>
    /// 绑定UI显示--创建通知基类
    /// 继承 INotifyPropertyChanged(作用:当属性发生变化时,传递变化属性的值)
    /// </summary>
    public class NotifyPropertyBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void Notify([CallerMemberName] string propName = "")
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }

        protected void SetProperty<T>(ref T prop, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(prop, value) == false)
            {
                prop = value;
                Notify(propertyName);
            }
        }
    }
}

3.运行结果

相关推荐
baivfhpwxf202329 分钟前
DataGrid 中增加选择列 功能实现
ui·wpf
CSharp精选营1 小时前
Dispose 不释放?C# 资源泄漏的 3 种隐蔽场景排查
c#·资源泄漏
unicrom_深圳市由你创科技3 小时前
LabVIEW和C#在工业控制中的应用差异是什么?
fpga开发·c#·labview
唐青枫4 小时前
C#.NET Consul + Steeltoe 深入解析:服务注册发现、健康检查与微服务接入
c#·.net
czhc11400756634 小时前
winform 330 跨线程 异步
wpf·线程·winform
DowneyJoy4 小时前
【Unity3D补充知识点】常用数据结构分析-集合(List<T>)
数据结构·unity·c#·list
格林威4 小时前
Baumer相机铝型材表面划伤长度测量:实现损伤量化评估的 5 个关键技术,附 OpenCV+Halcon 实战代码!
开发语言·人工智能·数码相机·opencv·计算机视觉·c#·工业相机
DowneyJoy5 小时前
【Unity3D补充知识点】常用数据结构分析-数组(Array)
数据结构·unity·c#
格林威5 小时前
Baumer相机铝箔表面针孔检测:提升包装阻隔性的 7 个核心策略,附 OpenCV+Halcon 实战代码!
开发语言·人工智能·数码相机·opencv·计算机视觉·c#·工业相机
想你依然心痛5 小时前
HarmonyOS 5.0教育行业解决方案:基于分布式能力的沉浸式智慧课堂系统
分布式·wpf·harmonyos