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

相关推荐

  1. vue数据

    2024-04-07 10:50:02       57 阅读
  2. vuekey

    2024-04-07 10:50:02       39 阅读

最近更新

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

    2024-04-07 10:50:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-07 10:50:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-07 10:50:02       82 阅读
  4. Python语言-面向对象

    2024-04-07 10:50:02       91 阅读

热门阅读

  1. 机器学习——卷积神经网络的反向传播算法

    2024-04-07 10:50:02       43 阅读
  2. WPF封装一个鼠标事件控件界面框选的功能

    2024-04-07 10:50:02       55 阅读
  3. 算法| ss 二叉树

    2024-04-07 10:50:02       37 阅读
  4. 软件工程,系统设计

    2024-04-07 10:50:02       36 阅读
  5. 软件工程

    2024-04-07 10:50:02       32 阅读
  6. 【C语言】生命周期&作用域选择题

    2024-04-07 10:50:02       39 阅读
  7. 深入解析Python的lxml库:高效处理XML和HTML的利器

    2024-04-07 10:50:02       39 阅读
  8. 创建线程的几种方式,及线程的生命周期?

    2024-04-07 10:50:02       34 阅读
  9. 数码视讯Q7盒子刷armbian遇到的坑之二

    2024-04-07 10:50:02       38 阅读
  10. 实现精简的通用环形缓冲器或环形队列

    2024-04-07 10:50:02       39 阅读