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

相关推荐
林川~017 小时前
Unity 万能物理检测工具:射线检测 / 范围检测 / 层级过滤 / 编辑器可视化(可直接拿去用)
游戏·unity·c#·射线检测·通用工具
He BianGu11 小时前
【WPF-VisionMaster】机器视觉通用平台V5.0版本发行说明
opencv·c#·wpf·halcon·机器视觉·visionmaster
tang_042711 小时前
【Hi.Ltd 专题】第9期:Interop 配置互操作(JSON/INI/XML/YAML/注册表/扫码)
经验分享·c#·hi.ltd系列
tang_042717 小时前
【Hi.Ltd 专题】第7期:Threading 采集线程、锁与 LRU 缓存
经验分享·c#·hi.ltd系列
A_nanda17 小时前
C# 界面卡顿:从定位到根治
c#
2501_9307077818 小时前
使用C#代码为新创建的 Word 文档创建目录
c#·word
czhc114007566319 小时前
同一个数,两把尺子:六组“看着一样、其实不一样“
c#
花北城20 小时前
【C#底层库】access_token授权鉴权验证
c#·鉴权·token·授权
rick97721 小时前
C# 动态代理与 DispatchProxy:从原理到实战的完整指南
c#
tang_042721 小时前
【Hi.Ltd 专题】第8期:Managements 插件、单例与服务定位
经验分享·c#·hi.ltd系列