c# wpf LiveCharts 简单试验2

1.概要

1.1 说明

1.2 要点

1.2.1 添加命名控件

复制代码
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"

1.2.2 图片控件

复制代码
<lvc:CartesianChart Name="chart"  LegendLocation="Right"/>

1.3 代码文件引用

复制代码
using LiveCharts.Wpf;
using LiveCharts.Wpf.Charts.Base;

1.4 数据绑定函数

复制代码
private void initView()
{
    SeriesCollection series = new SeriesCollection()
    {
        new LineSeries
        {
            Values = new ChartValues<double> {254,568,563,482,263,104 },
            Fill=new SolidColorBrush(Colors.IndianRed),
        },

    };
    chart.Series = series;
}

2.代码

复制代码
<Window x:Class="WpfApp3.Window1"
        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="Window1" Height="450" Width="800">
    <Grid>
        <lvc:CartesianChart Name="chart"  LegendLocation="Right"/>
    </Grid>
</Window>

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

namespace WpfApp3
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            initView();
        }
        private void initView()
        {
            SeriesCollection series = new SeriesCollection()
            {
                new LineSeries
                {
                    Values = new ChartValues<double> {254,568,563,482,263,104 },
                    Fill=new SolidColorBrush(Colors.IndianRed),
                },

            };
            chart.Series = series;
        }
    }
}

3.运行结果

相关推荐
Java林间1 天前
Zookeeper是什么?基于zookeeper实现分布式锁
分布式·zookeeper·wpf
zizisuo2 天前
1.微服务拆分与通信模式
微服务·wpf
程序员秘密基地2 天前
基于c#,wpf,ef框架,sql server数据库,音乐播放器
sql·sqlserver·c#·.net·wpf
Zhen (Evan) Wang2 天前
.NET 6 WPF 利用CefSharp.Wpf.NETCore显示PDF文件
.net·wpf·.netcore
冰茶_3 天前
WPF特性分析
学习·microsoft·c#·wpf
qq_196055873 天前
最快打包WPF 应用程序
wpf
baivfhpwxf20235 天前
wpf ScaleTransform
wpf
C#_西哥5 天前
wpf stylet框架 关于View与viewmodel自动关联绑定的问题
wpf
wqq10275 天前
WPF 图标原地旋转
wpf
续亮~5 天前
基于Redis实现RAG架构的技术解析与实践指南
java·redis·架构·wpf·springai·文档检索