当前位置: 首页 > news >正文

WPF Live Charts2 自学笔记

文章目录

  • 前言
    • 实现效果
    • 微软平台的历史问题
  • WPF 项目搭建
    • Nuget添加
    • 额外框架添加
    • 项目初始化
    • livecharts配置
    • 其它LiveCharts2 案例
    • 简单案例Demo示例
      • View
      • ViewModel
    • GPU渲染
  • Github地址仓库

前言

LiveChart 是C# 上面很受欢迎的统计图 UI控件。最近在学WPF+halcon开发,想想还是把LiveCharts 也顺便学一下

LiveCharts2 官网

LiveCharts2 WPF 平台官方文档

Gitee仓库地址 gclove2000 / WPF_LiveCharts2

在这里插入图片描述

实现效果

在这里插入图片描述

微软平台的历史问题

微软推出这么多UI框架干嘛。我希望MAUI在5年内不变。先把跨平台的问题解决好。
在这里插入图片描述

WPF 项目搭建

Nuget添加

注意:Livecharts2 目前是预览版,所以需要在搜索的时候添加预览版选项
在这里插入图片描述

LiveChartsCore.SkiaSharpView.WPF

在这里插入图片描述

额外框架添加

在这里插入图片描述

WPF Prims框架详解

WPF CommunityToolkit.Mvvm

项目初始化

按照案例运行完美成功!

ViewModel属性添加

using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;namespace WpfSample
{public class ViewModel{public ISeries[] Series { get; set; } = new ISeries[]{new LineSeries<double>{Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },Fill = null}};}
}

xml添加

<Window x:Class="MyApp"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WPFSample"xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"><Window.DataContext><local:ViewModel /></Window.DataContext><lvc:CartesianChartSeries="{Binding Series}"></lvc:CartesianChart></Window>

在这里插入图片描述
运行效果
在这里插入图片描述

livecharts配置

看不懂,暂时不用
在这里插入图片描述

其它LiveCharts2 案例

我们可以在LiveCharts2的Example里面选择案例
常用的:条形图,柱状图,雷达塔,世界地图等都有,而且都有对应的动态动画
在这里插入图片描述
在这里插入图片描述

简单案例Demo示例

在这里插入图片描述

View

<UserControl x:Class="BlankApp1.Views.AView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:local="clr-namespace:BlankApp1.Views"xmlns:ViewModel="clr-namespace:BlankApp1.ViewModels"xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"mc:Ignorable="d"d:DesignHeight="450"d:DesignWidth="800"><UserControl.DataContext><ViewModel:AViewModel /></UserControl.DataContext><Grid><Grid.RowDefinitions><RowDefinition /><RowDefinition /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition /></Grid.ColumnDefinitions><lvc:CartesianChart Series="{Binding Series}"Grid.Row="0"Grid.Column="0" /><lvc:CartesianChart Series="{Binding Series2}"Grid.Row="0"Grid.Column="1"YAxes="{Binding YAxes2}" /><lvc:PieChart Series="{Binding Series3}"Grid.Row="1"Grid.Column="0"Title="{Binding Title3}"></lvc:PieChart><lvc:PieChart Grid.Row="1"Grid.Column="1"Series="{Binding Series4}" /></Grid>
</UserControl>

ViewModel

using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using System.Windows.Ink;
using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore.SkiaSharpView.VisualElements;namespace BlankApp1.ViewModels
{partial class AViewModel : ObservableObject{public AViewModel() {var outer = 0;var data = new[] { 6, 5, 4, 3, 2 };// you can convert any array, list or IEnumerable<T> to a pie series collection:Series4 = data.AsPieSeries((value, series) =>{// this method is called once per element in the array// we are decrementing the outer radius 50px// on every element in the array.series.InnerRadius = 50;series.OuterRadiusOffset = outer;outer += 50;});}[ObservableProperty]private string title = "ViewA";public ISeries[] Series { get; set; }= new ISeries[]{new LineSeries<double>{Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },Fill = null}};public ISeries[] Series2 { get; set; } ={new ColumnSeries<double>{IsHoverable = false, // disables the series from the tooltips Values = new double[] { 10, 10, 10, 10, 10, 10, 10 },Stroke = null,Fill = new SolidColorPaint(new SKColor(30, 30, 30, 30)),IgnoresBarPosition = true},new ColumnSeries<double>{Values = new double[] { 3, 10, 5, 3, 7, 3, 8 },Stroke = null,Fill = new SolidColorPaint(SKColors.CornflowerBlue),IgnoresBarPosition = true}};public Axis[] YAxes2 { get; set; } ={new Axis { MinLimit = 0, MaxLimit = 10 }};public IEnumerable<ISeries> Series3 { get; set; } =new[] { 2, 4, 1, 4, 3 }.AsPieSeries();public LabelVisual Title3 { get; set; } =new LabelVisual{Text = "My chart title",TextSize = 25,Padding = new LiveChartsCore.Drawing.Padding(15),Paint = new SolidColorPaint(SKColors.DarkSlateGray)};public IEnumerable<ISeries> Series4 { get; set; }}
}

GPU渲染

我听说LiveCharts2是用GPU渲染的,发现好像是真的
在这里插入图片描述

Github地址仓库

Gitee仓库地址 gclove2000 / WPF_LiveCharts2

http://www.lryc.cn/news/251397.html

相关文章:

  • 大小堆的实现(C语言)
  • Linux系统之centos7编译安装Python 3.8
  • Lambda表达式与方法引用
  • 二维数组处理(一)
  • 基于JNI实现调用C++ SDK
  • 计算机组成原理笔记——存储器(静态RAM和动态RAM的区别,动态RAM的刷新, ROM……)
  • 企业计算机服务器locked1勒索病毒数据恢复,locked1勒索病毒解密流程
  • Session 与 JWT 的对决:谁是身份验证的王者? (下)
  • 论文笔记:Confidential Assets
  • Docker下搭建MySQL主从复制
  • VBA数据库解决方案第七讲:如何利用Recordset对象打开数据库的数据记录集
  • 内部培训平台的系统 PlayEdu搭建私有化内部培训平台
  • Elasticsearch 相似度评分模型介绍
  • 视频生成的发展史及其原理解析:从Gen2、Emu Video到PixelDance、SVD、Pika 1.0
  • SQL Server 2016(基本概念和命令)
  • Linux C语言 30-套接字操作
  • RPC和REST对比
  • 外包干了2年,技术退步明显。。。
  • 深度学习——第1章 深度学习的概念及神经网络的工作原理
  • 爬虫爬取百度图片、搜狗图片
  • Android Camera2使用
  • IOS/安卓+charles实现抓包(主要解决证书网站无法打开问题)
  • 七、Lua字符串
  • 0基础学java-day13
  • 好题记录:
  • web前端之JavaScrip中的闭包
  • Windows下命令行启动与关闭WebLogic的相关服务
  • LeetCode Hot100 169.多数元素
  • 数据结构:堆的实现思路
  • 结合 DBSCAN 示例代码介绍 DBSCAN