c# wpf LiveCharts MVVM绑定 简单试验

1.概要

c# wpf LiveCharts MVVM绑定 简单试验

2.代码

<Window x:Class="WpfApp3.Window3"
        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="Window3" Height="450" Width="800">
    <Grid>
        <lvc:CartesianChart Margin="10" LegendLocation="Bottom">
            <lvc:CartesianChart.Series>
                <lvc:LineSeries  Fill="#DBF3F9" Stroke="#5CD0E1" Title="消费"
                        Values="{Binding SeriesValues}" PointGeometrySize="0" DataLabels="True"/>
            </lvc:CartesianChart.Series>
            <lvc:CartesianChart.AxisX>
                <lvc:Axis Labels="{Binding SeriesLabels}" Margin="10">
                    <lvc:Axis.Separator>
                        <lvc:Separator StrokeThickness="0.5" Step="1" />
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX>
            <lvc:CartesianChart.AxisY>
                <lvc:Axis MinValue="0" ShowLabels="True"/>
            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>
    </Grid>
</Window>

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 LiveCharts.Wpf;

namespace WpfApp3
{
    /// <summary>
    /// Window3.xaml 的交互逻辑
    /// </summary>
    public partial class Window3 : Window
    {
        public Window3()
        {
            InitializeComponent();
            this.DataContext = new HomePgVM2();
        }
    }
    public class HomePgVM2 : NotifyPropertyBase
    {
        public ChartValues<double> SeriesValues { get; set; }
        public string[] SeriesLabels { get; set; }

        public HomePgVM2()
        {
            SeriesValues = new ChartValues<double>();
            double[] dValues = new double[] { 581, 423, 634, 658, 134, 256, 318 };
            SeriesLabels = new[] { "8-1", "8-2", "8-3", "8-4", "8-5", "8-6", "8-7" };
            for (int i = 0; i < dValues.Length; i++)
            {
                SeriesValues.Add(dValues[i]);
            }
        }

    }
}

3.运行结果

相关推荐
软件黑马王子3 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
水煮庄周鱼鱼7 小时前
C# 入门简介
开发语言·c#
软件黑马王子8 小时前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
Nicole Potter9 小时前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
code_shenbing9 小时前
WPF实现打印机控制及打印
wpf
gu2010 小时前
c#编程:学习Linq,重几个简单示例开始
开发语言·学习·c#·linq
pchmi15 小时前
CNN常用卷积核
深度学习·神经网络·机器学习·cnn·c#
yuanpan15 小时前
23种设计模式之《组合模式(Composite)》在c#中的应用及理解
开发语言·设计模式·c#·组合模式
滴_咕噜咕噜16 小时前
C#基础总结:常用的数据结构
开发语言·数据结构·c#
万兴丶20 小时前
Unity 适用于单机游戏的红点系统(前缀树 | 数据结构 | 设计模式 | 算法 | 含源码)
数据结构·unity·设计模式·c#