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.运行结果

相关推荐
IT规划师19 分钟前
C#|.net core 基础 - 扩展数组添加删除性能最好的方法
c#·.netcore·数组
时光追逐者1 小时前
分享6个.NET开源的AI和LLM相关项目框架
人工智能·microsoft·ai·c#·.net·.netcore
friklogff1 小时前
【C#生态园】提升C#开发效率:深入了解自然语言处理库与工具
开发语言·c#·区块链
__water10 小时前
『功能项目』回调函数处理死亡【54】
c#·回调函数·unity引擎
__water10 小时前
『功能项目』眩晕图标显示【52】
c#·unity引擎·动画事件
__water11 小时前
『功能项目』第二职业法师的平A【57】
c#·unity引擎·魔法球伤害传递
__water13 小时前
『功能项目』战士的伤害型技能【45】
c#·unity引擎·战士职业伤害型技能
君莫愁。14 小时前
【Unity】检测鼠标点击位置是否有2D对象
unity·c#·游戏引擎
Lingbug15 小时前
.Net日志组件之NLog的使用和配置
后端·c#·.net·.netcore
咩咩觉主15 小时前
Unity实战案例全解析:PVZ 植物卡片状态分析
unity·c#·游戏引擎