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

相关推荐
c#上位机12 分钟前
halcon刚性变换(平移+旋转)——vector_angle_to_rigid
人工智能·计算机视觉·c#·上位机·halcon·机器视觉
小码编匠24 分钟前
WPF 实现高仿 Windows 通知提示框:工业级弹窗设计与实现
后端·c#·.net
SEO-狼术36 分钟前
Telerik UI for WPF and WinForms 2025 Q4 Crack
ui·wpf
武藤一雄2 小时前
[WPF] 万字拆解依赖属性与附加属性
前端·microsoft·c#·.net·wpf
Macbethad2 小时前
工业设备配方管理程序技术方案
wpf
我好喜欢你~2 小时前
.net---图表库(LiveCharts.Wpf)
c#·wpf
helloworddm2 小时前
GrainType详解
服务器·网络·架构·c#
yngsqq2 小时前
CAD点集生成泰森多边形Voronoi图)——CAD二次开发
c#
武藤一雄2 小时前
C#:深入浅出委托(Delegate/Func/Action/Predicate)
开发语言·后端·microsoft·微软·c#·.net
500843 小时前
鸿蒙 Flutter 分布式数据同步:DistributedData 实时协同实战
分布式·flutter·华为·electron·开源·wpf·音视频