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

相关推荐
z落落1 小时前
C# 多接口实现、重名成员、显式实现、接口继承+抽象类和接口区别
java·开发语言·c#
咸鱼翻身小阿橙1 小时前
高斯模糊降噪/磨皮算法降噪图像
前端·opencv·算法·webpack·c#
Song_da_da_12 小时前
C#与VisionPro联合编程实战:机器视觉二次开发完整指南
开发语言·microsoft·c#
加号315 小时前
【C#】 Web API 自定义配置函数请求路径:从路由本质到灵活架构设计
开发语言·c#
happyprince18 小时前
11-Hugging Face Transformers 分布式与并行系统深度分析
分布式·c#·wpf
csdn_aspnet19 小时前
C# list集合 多属性排序
c#·list·linq·排序
加号319 小时前
【WPF】 基于 Canvas 读取并渲染 DXF 文件的技术指南
c#·wpf
天下无敌笨笨熊20 小时前
SNMP协议开发心得
网络协议·c#
创可贴治愈心灵20 小时前
AI浪潮下C#就业前景剖析:深耕C#为主,按需选修Java与Python
java·人工智能·c#
专注VB编程开发20年1 天前
开发VS2026插件最佳方案:老式VSIX EnvDTE
ide·c#·visual studio