c# wpf LiveCharts 饼图 简单试验

1.概要

c# wpf LiveCharts 饼图 简单试验

2.代码

复制代码
<Window x:Class="WpfApp3.Window5"
        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="Window5" Height="450" Width="800">
    <Grid>
        <lvc:PieChart Height="220" InnerRadius="20" Margin="5"
                        Series="{Binding PieSeriesCollection}" LegendLocation="Right" >
            <lvc:PieChart.ChartLegend>
                <lvc:DefaultLegend BulletSize="10"></lvc:DefaultLegend>
            </lvc:PieChart.ChartLegend>
            <lvc:PieChart.DataTooltip>
                <lvc:DefaultTooltip BulletSize="10"></lvc:DefaultTooltip>
            </lvc:PieChart.DataTooltip>
        </lvc:PieChart>
    </Grid>
</Window>

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

namespace WpfApp3
{
    /// <summary>
    /// Window5.xaml 的交互逻辑
    /// </summary>
    public partial class Window5 : Window
    {
        public Window5()
        {
            InitializeComponent();
            this.DataContext = new HomePgVM4();
        }
    }
    public class HomePgVM4 : NotifyPropertyBase
    {

        public SeriesCollection PieSeriesCollection { get; set; }

        public HomePgVM4()
        {
            GetPie();
        }
        private void GetPie()
        {
            PieSeriesCollection = new SeriesCollection();
            double[] pieValues = new double[] { 25, 36, 85, 45, 69, 45, 85 };
            for (int i = 0; i < pieValues.Length; i++)
            {
                PieSeriesCollection.Add(new PieSeries
                {
                    Title = "商户 -- " + i,
                    Values = new ChartValues<double> { pieValues[i] },
                    DataLabels = true,
                });
            }
        }
    }
}

3.运行结果

相关推荐
还在忙碌的吴小二8 分钟前
Harness 最佳实践:Java Spring Boot 项目落地 OpenSpec + Claude Code
java·开发语言·spring boot·后端·spring
liliangcsdn9 分钟前
mstsc不在“C:\Windows\System32“下在C:\windows\WinSxS\anmd64xxx“问题分析
开发语言·windows
小陈工20 分钟前
2026年4月7日技术资讯洞察:下一代数据库融合、AI基础设施竞赛与异步编程实战
开发语言·前端·数据库·人工智能·python
KAU的云实验台22 分钟前
【算法精解】AIR期刊算法IAGWO:引入速度概念与逆多元二次权重,可应对高维/工程问题(附Matlab源码)
开发语言·算法·matlab
会编程的土豆29 分钟前
【数据结构与算法】再次全面了解LCS底层
开发语言·数据结构·c++·算法
jerryinwuhan40 分钟前
RDD第二次练习
开发语言·c#
wechat_Neal42 分钟前
Golang的车载应用场景
开发语言·后端·golang
晓纪同学1 小时前
WPF-03 第一个WPF程序
大数据·hadoop·wpf
weixin_513449961 小时前
walk_these_ways项目学习记录第八篇(通过行为多样性 (MoB) 实现地形泛化)--策略网络
开发语言·人工智能·python·学习
飞Link1 小时前
逆向兼容的桥梁:3to2 自动化降级工具实现全解析
运维·开发语言·python·自动化