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

相关推荐
成都易yisdong5 小时前
纬地、鸿业、海地、CASS等横断面数据互转工具V3.2——测绘与道路设计人员的效率神器
c#·visual studio code
AIKZX8 小时前
西门子博途 TIA Portal v18 中文版图文安装教程(超级详细)附下载链接
开发语言·c#·编辑器·idea
xiaoshuaishuai810 小时前
C# 数字资源分发
开发语言·c#
格林威12 小时前
面阵相机 vs 线阵相机:堡盟与Basler选型差异全解析 +C# 实战演示
开发语言·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
少控科技12 小时前
小数典 - V1.0.0.1
windows·c#
格林威13 小时前
面阵相机 vs 线阵相机:堡盟与海康相机选型差异全解析 附C# 实战演示
开发语言·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
刘~浪地球14 小时前
日志平台架构设计
c#·linq
c#上位机14 小时前
wpf附加事件
wpf
玖笙&14 小时前
✨WPF编程进阶【9.1】:WPF资源完全指南(附源码)
c++·c#·wpf·visual studio
想你依然心痛14 小时前
HarmonyOS 6(API 23)分布式实战:基于悬浮导航与沉浸光感的“光影协创“跨设备白板系统
分布式·wpf·harmonyos·悬浮导航·沉浸光感