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

相关推荐
self_myth17 小时前
[特殊字符] 深入理解操作系统核心特性:从并发到分布式,从单核到多核的全面解析
windows·macos·wpf·harmonyos
c#上位机18 小时前
wpf之TextBlock
c#·wpf
玉面小君2 天前
从 WPF 到 Avalonia 的迁移系列实战篇6:ControlTheme 和 Style区别
c#·wpf·avalonia
c#上位机2 天前
wpf之Border
c#·wpf
SunflowerCoder2 天前
WPF迁移avalonia之图像处理(一)
图像处理·wpf·avalonia
周杰伦fans3 天前
WPF中的DataContext以及常见的绑定方式
wpf
没有bug.的程序员3 天前
Redis 数据结构全面解析:从底层编码到实战应用
java·数据结构·redis·wpf
somethingGoWay4 天前
wpf 自定义输入ip地址的文本框
wpf
秋月的私语4 天前
Wpf程序屏幕居中问题修复全记录
wpf
我要打打代码4 天前
WPF启动窗体的三种方式
wpf