WPF Live Charts2 自学笔记

news2024/9/22 1:26:55

文章目录

  • 前言
    • 实现效果
    • 微软平台的历史问题
  • 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:CartesianChart
        Series="{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.coloradmin.cn/o/1264639.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【.NET全栈】.net的微软API接口与.NET框架源码

文章目录 0 前言1 微软官方.net接口学习2 .NET框架源码总结 0 前言 如果浏览器打不开链接&#xff0c;换一个浏览器打开。 我是 打不开微软的链接&#xff0c;使用&#xff1a; 可以打开&#xff01;&#xff01;&#xff01; 1 微软官方.net接口学习 https://docs.microsoft…

【藏经阁一起读】(78)__《Apache Tomcat 的云原生演进》

【藏经阁一起读】&#xff08;78&#xff09; __《Apache Tomcat 的云原生演进》 目录 __《Apache Tomcat 的云原生演进》 一、读后感 二、文章知识点摘要 2.1、Tomcat的技术内幕和在喜马拉雅的实践 2.2、GraalVM static compilation in web container application&…

windows系统mobaxterm远程执行linux上ssh命令

命令如下 start "" "%~dp0\MobaXterm_Personal_23.4.exe" -newtab "sshpass -p root ssh root192.168.11.92 mkdir 33" -p 是密码 左边是用户名&#xff0c;右边是服务器ip 后面跟的是服务器上执行的命令 第一次执行的时候要设置mobaxt…

海翔云平台 getylist_login.do SQL 注入漏洞复现

0x01 产品简介 海翔云平台一站式整体解决方案提供商&#xff0c;业务涵盖 批发、连锁、零售行业ERP解决方案、wms仓储解决方案、电商、外勤、移动终端&#xff08;PDA、APP、小程序&#xff09;解决方案。 0x02 漏洞概述 海翔云平台getylist_login.do接口处存在SQL注入漏洞&am…

《数据结构、算法与应用C++语言描述》-线索二叉树的定义与C++实现

_23Threaded BinaryTree 可编译运行代码见&#xff1a;GIithub::Data-Structures-Algorithms-and-Applications/_24Threaded_BinaryTree 线索二叉树定义 在普通二叉树中&#xff0c;有很多nullptr指针被浪费了&#xff0c;可以将其利用起来。 首先我们要来看看这空指针有多少…

老师怎样预防校园欺凌的发生

作为老师&#xff0c;面对校园欺凌这个问题&#xff0c;我觉得有必要为各位老师提供一些实用的建议和策略。因为大家都知道&#xff0c;校园欺凌的存在不仅会对学生造成身心伤害&#xff0c;还会对整个教育环境产生负面影响。 关注学生的心理健康 校园欺凌往往与学生的心理问题…

手把手教你:基于python+Django的英文数据分析与可视化系统

系列文章 手把手教你&#xff1a;基于Django的新闻文本分类可视化系统&#xff08;文本分类由bert实现&#xff09;手把手教你&#xff1a;基于python的文本分类&#xff08;sklearn-决策树和随机森林实现&#xff09;手把手教你&#xff1a;基于TensorFlow的语音识别系统 目录…

Java Agent探针技术

前言 Java Agent基于字节码增强技术研发&#xff0c;支持自动埋点完成数据上报&#xff0c;Java Agent包含(并二次分发)opentelemetry-java-instrumentation CNCF的开源代码&#xff0c;遵循Apache License 2.0协议&#xff0c;在Java Agent包中对opentelemetry License进行了…

为什么国密SSL证书越来越受市场青睐

随着信息技术的迅猛发展&#xff0c;网络安全问题备受关注。在这个背景下&#xff0c;越来越多的单位纷纷选择国密SSL证书&#xff0c;以构建更为安全可靠的网络环境。那么&#xff0c;为什么这么多单位选择国密SSL证书呢&#xff1f; 1&#xff0c;国家政策支持 近年来&#…

战略制定|竞争战略管理分析六大常用工具

企业战略可从多个角度理解&#xff0c;体现为著名的5P模型。首先&#xff0c;从未来发展视角看&#xff0c;战略是一种计划(Plan)&#xff0c;指导企业朝向既定目标前进。而从过去的发展历程看&#xff0c;它呈现为一种模式(Pattern)&#xff0c;反映了企业的历史行为趋势。在产…

【Python】Selenium自动化测试框架

设计思路 本文整理归纳以往的工作中用到的东西&#xff0c;现汇总成基础测试框架提供分享。 框架采用python3 selenium3 PO yaml ddt unittest等技术编写成基础测试框架&#xff0c;能适应日常测试工作需要。 1、使用Page Object模式将页面定位和业务操作分开&#xff0…

uniapp+微信小程序监听返回事件

代码附在最后 适用场景&#xff1a;uniapp开发微信小程序 需求是我点击列表进入数据信息的详情界面&#xff0c;点击详情界面的收藏&#xff0c;返回上一界面后&#xff0c;更新列表中的收藏情况。 目录 一、使用onUnload监听页面卸载 二、使用getCurrentPages()获取当前页…

关于网站的favicon.ico图标的设置需要注意的几点

01-必须在网页的head标签中放上下面的说明&#xff1a; <link rel"shortcut icon" href"/favicon.ico">否则&#xff0c;浏览器虽然能读到图标&#xff0c;但是不会把图标显示在标签上。 02-浏览器会默认到网站根目录中读取文件favicon.ico&#x…

Java线程通信

线程通信 案例 package com.itheima.d4;public class ThreadTest {public static void main(String[] args) {Desk desk new Desk();//创建3个生产者线程new Thread(() -> {while (true) {desk.put();}}, "厨师1").start();new Thread(() -> {while (true) {…

MySQL数据库入门到大牛_基础_18_MySQL8其它新特性(MySQL基础部分最后一章;新特性概述;窗口函数;公用表表达式)

文章目录 1. MySQL8新特性1.1 MySQL8.0 新增特性1.2 MySQL8.0移除的旧特性 2. 新特性1&#xff1a;窗口函数2.1 使用窗口函数前后对比2.2 窗口函数分类2.3 语法结构2.4 分类讲解1. 序号函数2. 分布函数3. 前后函数4. 首尾函数5. 其他函数 2.5 小 结 3. 新特性2&#xff1a;公用…

vsphere系列 :虚拟机配置直通GPU后,启动时出现 模块“DevicePowerOn”打开电源失败 的解决方案

vsphere中的虚拟机配置直通GPU后&#xff0c;启动时出现 模块“DevicePowerOn”打开电源失败 的解决方案 vsphere中的虚拟机配置直通GPU后&#xff0c;启动时出现 模块“DevicePowerOn”打开电源失败 的解决方案1、虚拟机配置GPU直通1、打开虚拟机选项2、点击编辑配置3、添加如…

SpringBoot+VUE3前后端分离-【支付宝支付】

1、支付宝沙箱应用申请 https://open.alipay.com/develop/sandbox/app 打开支付宝沙箱能够看到如下信息&#xff1a; 获取到appid&#xff1b; 2、获取应用私钥以及支付宝公钥 在接口加密方式选择公钥模式启用&#xff0c;根据操作即可获取应用公钥、应用私钥以及支付宝公钥…

别再让假的fiddler教程毒害你了,来看这套最全最新的fiddler全工具讲解

fiddler界面工具栏介绍 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; &#xff08;1&#xff09;WinConfig&#xff1a;windows 使用了一种叫做“AppContainer”的隔离技术&#xff0c;使得一些流量无法正常捕获&#xff0c;在 fiddler中点击 WinConfig…

【蓝桥杯选拔赛真题26】C++字符串逆序 第十三届蓝桥杯青少年创意编程大赛C++编程选拔赛真题解析

目录 C/C++字符串逆序 一、题目要求 1、编程实现 2、输入输出 二、算法分析

Web框架与Django路由层

Web框架 一 web框架 Web框架&#xff08;Web framework&#xff09;是一种开发框架&#xff0c;用来支持动态网站、网络应用和网络服务的开发。这大多数的web框架提供了一套开发和部署网站的方式&#xff0c;也为web行为提供了一套通用的方法。web框架已经实现了很多功能&…