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

Avalonia常用小控件Charts

1.项目下载地址:https://gitee.com/confusedkitten/avalonia-demo
2.UI库Semi.Avalonia,项目地址  https://github.com/irihitech/Semi.Avalonia

3.Charts库,LiveChartsCore.SkiaSharpView.Avalonia,Nuget获取只有预览库,也没找到别的啥好用的库

4.样式预览:

5.Charts.axaml

<UserControl xmlns="https://github.com/avaloniaui"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"mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"xmlns:vm="using:AvaloniaDemo.ViewModels"x:Class="AvaloniaDemo.Pages.Charts"x:DataType="vm:StatisticsViewModel"><Grid RowDefinitions="*,*"><lvc:PieChart Name="ryredpie" FontFamily="Microsoft YaHei" Series="{Binding DamageSeries}" LegendPosition="Right" ></lvc:PieChart><lvc:CartesianChart  Name="ryredaxisx" Grid.Row="1"  Series="{Binding VictorySeries}" XAxes="{Binding VictoryXAxes}"><lvc:CartesianChart.Tooltip><vm:CustomTooltip></vm:CustomTooltip></lvc:CartesianChart.Tooltip></lvc:CartesianChart></Grid>
</UserControl>

6.Charts.axaml.cs 

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using AvaloniaDemo.ViewModels;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.SkiaSharpView.SKCharts;
using SkiaSharp;
using System.Reflection.Metadata;namespace AvaloniaDemo.Pages;public partial class Charts : UserControl
{public const string DefaultFontFamily = "Microsoft YaHei";private StatisticsViewModel viewModel = new StatisticsViewModel(new SolidColorPaint(SKColor.Parse("#4992FF")));public Charts(){InitializeComponent();DataContext = viewModel;InitLegend();}/// <summary>/// 改图例字体,默认不支持中文/// </summary>private void InitLegend(){try{if (ryredpie.Legend is SKDefaultLegend skDefaultLegend){skDefaultLegend.TextSize = 13;if (skDefaultLegend.FontPaint is Paint paint){paint.FontFamily = Constant.DefaultFontFamily;paint.Color = new SKColor(255, 255, 255);}}if (ryredpie.Tooltip is SKDefaultTooltip skDefaultTooltip){if (skDefaultTooltip.FontPaint is Paint paint){paint.FontFamily = Constant.DefaultFontFamily;paint.Color = new SKColor(255, 255, 255);}}ryredpie.TooltipPosition = TooltipPosition.Right;}catch { }}
}

 7.StatisticsViewModel.cs

using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;namespace AvaloniaDemo.ViewModels
{public class StatisticsViewModel : ViewModelBase{SolidColorPaint _solidColor { get; set; } = new SolidColorPaint(SKColor.Parse("#4992FF"));public StatisticsViewModel(SolidColorPaint solidColor){_solidColor = solidColor;((ColumnSeries<int>)_VictorySeries.ElementAt(0)).Fill = _solidColor;}public StatisticsViewModel(){}/// <summary>/// 饼图内径/// </summary>public static int PieInnerRadius = 35;#region 统计public Axis[] VictoryXAxes { get; set; } ={new Axis{Labels = new[] { "正常", "轻伤", "中伤", "重伤", "死亡" },LabelsRotation = 0,LabelsPaint=new SolidColorPaint(new SKColor(255, 255, 255)){FontFamily="Microsoft YaHei",},TextSize=12,LabelsAlignment=Align.Middle,TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),TicksAtCenter = true,MinStep = 1,ForceStepToMin = true,}};private ObservableCollection<ISeries> _VictorySeries = new ObservableCollection<ISeries>{new ColumnSeries<int> { Values = new int[] { 5,8,1,0,9 },Fill=  new SolidColorPaint(SKColor.Parse("#4992FF"))},};private ISeries[] _DamageSeries = new ISeries[]{new PieSeries<int> { Values = new int[] { 2 }, Name = "正常" ,InnerRadius=PieInnerRadius, Fill=  new SolidColorPaint(SKColor.Parse("#008000"))},new PieSeries<int> { Values = new int[] { 4 }, Name = "轻伤" ,InnerRadius=PieInnerRadius, Fill=  new SolidColorPaint(SKColor.Parse("#D2C86B")) },new PieSeries<int> { Values = new int[] { 1 }, Name = "中伤" ,InnerRadius=PieInnerRadius, Fill=  new SolidColorPaint(SKColor.Parse("#03AEDE")) },new PieSeries<int> { Values = new int[] { 4 }, Name = "重伤" ,InnerRadius=PieInnerRadius, Fill=  new SolidColorPaint(SKColor.Parse("#C13530")) },new PieSeries<int> { Values = new int[] { 3 }, Name = "死亡" ,InnerRadius=PieInnerRadius, Fill=  new SolidColorPaint(SKColor.Parse("#696969")) }};public ObservableCollection<ISeries> VictorySeries{get => _VictorySeries;set => RaiseAndSetIfChanged(ref _VictorySeries, value);}public ISeries[] DamageSeries{get => _DamageSeries;set => RaiseAndSetIfChanged(ref _DamageSeries, value);}#endregion}
}

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

相关文章:

  • 【Hugging Face】管理 huggingface_hub 缓存系统
  • Python学习基础笔记六十六——对象的方法
  • 建立一个新的高阶数学教授模式,知其然,知其用,知其之所以然,知其所以然
  • AtCoder ABC324G 启发式合并
  • SpringBootCMS漏洞复现分析
  • iOS- flutter flavor 多环境Configurations配置
  • 【PyTorchTensorBoard实战】GPU与CPU的计算速度对比(附代码)
  • npm 常用指令总结
  • 布朗大学发现GPT-4存在新问题,可通过非常见语言绕过限制
  • ESP32网络编程-TCP客户端数据传输
  • 微信小程序入门级
  • 博客文档续更(二)
  • Centos切换yum源
  • milvus和相似度检索
  • 龙迅LT7911UXC 是一款高性能TYPE-C/DP/EDP转换四端口MIPI/LVDS的芯片,还支持图像处理
  • TOR(Top of Rack)
  • 使用asp.net core web api创建web后台,并连接和使用Sql Server数据库
  • LaTeX 公式与表格绘制技巧
  • Spring Cloud--Nacos+@RefreshScope实现配置的动态更新
  • Elasticsearch安装
  • 【JavaSE API 】生成随机数的2种方法:Random类和Math类的Random方法
  • 微软和OpenAI正在开发AI芯片, 并计划下个月发布
  • 记一次Hbase2.1.x历史数据数据迁移方案
  • luajit简介
  • 1.2 switch实现两个数的四则运算
  • mysql面试题47:MySQL中Innodb的事务实现原理
  • Google云平台构建数据ETL任务的最佳实践
  • 【更新】囚生CYの备忘录(202331014~)
  • 《UnityShader入门精要》学习4
  • kaggle新赛:写作质量预测大赛【数据挖掘】