最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF仿LiveCharts實現(xiàn)餅圖的繪制

 更新時間:2022年07月29日 09:34:23   作者:驚鏵  
這篇文章主要介紹了如何利用WPF仿LiveCharts實現(xiàn)餅圖的繪制,文中的示例代碼講解詳細,對我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下

每日一笑

下班和實習(xí)生一起回家,公交站等車,一乞丐把碗推向?qū)嵙?xí)生乞討。這時,實習(xí)生不慌不忙的說了句:“我不要你的錢,你這錢來的也不容易。” 

前言 

有小伙伴需要統(tǒng)計圖。

效果預(yù)覽(更多效果請下載源碼體驗)

一、PieControl.cs

using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WpfPieControl.Models;

namespace WpfPieControl
{
    public class PieControl: Control
    {
        public ObservableCollection<PieSegmentModel> PieSegmentModels
        {
            get { return (ObservableCollection<PieSegmentModel>)GetValue(PieSegmentModelsProperty); }
            set { SetValue(PieSegmentModelsProperty, value); }
        }

        public static readonly DependencyProperty PieSegmentModelsProperty =
            DependencyProperty.Register("PieSegmentModels", typeof(ObservableCollection<PieSegmentModel>), typeof(PieControl), new UIPropertyMetadata(OnPieSegmentModelChanged));

        private static void OnPieSegmentModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PieControl pieControl = d as PieControl;
            if (e.NewValue != null)
            {
                var array = e.NewValue as ObservableCollection<PieSegmentModel>;
                double angleNum = 0;
                foreach (var item in array)
                {
                    var color = new SolidColorBrush((Color)ColorConverter.ConvertFromString(pieControl.ColorArray[array.IndexOf(item)]));
                    item.Color = color;
                    item.StartAngle = angleNum;
                    item.EndAngle = angleNum + item.Value / 100 * 360;
                    angleNum = item.EndAngle;
                }
            }
        }
        /// <summary>
        /// colors
        /// </summary>
        private string[] ColorArray = new string[] { "#FDC006", "#607E89", "#2095F2", "#F34336" };


        /// <summary>
        /// 0~1
        /// </summary>
        public double ArcThickness
        {
            get { return (double)GetValue(ArcThicknessProperty); }
            set { SetValue(ArcThicknessProperty, value); }
        }

        public static readonly DependencyProperty ArcThicknessProperty =
            DependencyProperty.Register("ArcThickness", typeof(double), typeof(PieControl), new PropertyMetadata(1.0));


        static PieControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(PieControl), new FrameworkPropertyMetadata(typeof(PieControl)));
        }
    }
}

二、App.xaml

<Style TargetType="{x:Type local:PieControl}">
            <Setter Property="UseLayoutRounding" Value="True" />
            <!--<Setter Property="Background" Value="#252525"/>-->
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Width" Value="250"/>
            <Setter Property="Height" Value="250"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:PieControl}">
                        <ItemsControl Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
                                      ItemsSource="{TemplateBinding PieSegmentModels}"
                                      Background="{TemplateBinding Background}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <Grid IsItemsHost="True"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <ed:Arc Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
                                                ArcThickness="{Binding ArcThickness,RelativeSource={RelativeSource FindAncestor,AncestorType=local:PieControl}}" ArcThicknessUnit="Percent"
                                                EndAngle="{Binding EndAngle}"
                                                StartAngle="{Binding StartAngle}"
                                                Stretch="None"
                                                ToolTip="{Binding Name}"
                                                Stroke="{Binding ColorStroke}"
                                                StrokeThickness="2"
                                                Fill="{Binding Color}">
                                    </ed:Arc>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
</Style>

三、MainWindow.xaml

<Window x:Class="WpfPieControl.MainWindow"
        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:local="clr-namespace:WpfPieControl"
        mc:Ignorable="d"
        Title="微信公眾號:WPF開發(fā)者" Height="450" Width="800">
    <StackPanel>
        <WrapPanel Margin="10">
            <local:PieControl PieSegmentModels="{Binding PieSegmentModels,RelativeSource={RelativeSource AncestorType=local:MainWindow}}" ArcThickness="1"/>
            <local:PieControl PieSegmentModels="{Binding PieSegmentModels,RelativeSource={RelativeSource AncestorType=local:MainWindow}}" 
                                  Margin="4,0"
                                  ArcThickness="{Binding ElementName=PRAT_Slider,Path=Value}"/>
            <local:PieControl PieSegmentModels="{Binding PieSegmentModels,RelativeSource={RelativeSource AncestorType=local:MainWindow}}" ArcThickness="0.65"/>
        </WrapPanel>
        <Slider Maximum="0.9" Minimum="0.1" x:Name="PRAT_Slider" Margin="10" Width="200"/>
        <Button Content="更新" Click="Button_Click" VerticalAlignment="Bottom" Width="200"/>
    </StackPanel>
</Window>

四、MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using WpfPieControl.Models;

namespace WpfPieControl
{
    /// <summary>
    /// MainWindow.xaml 的交互邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public ObservableCollection<PieSegmentModel> PieSegmentModels
        {
            get { return (ObservableCollection<PieSegmentModel>)GetValue(PieSegmentModelsProperty); }
            set { SetValue(PieSegmentModelsProperty, value); }
        }

        public static readonly DependencyProperty PieSegmentModelsProperty =
            DependencyProperty.Register("PieSegmentModels", typeof(ObservableCollection<PieSegmentModel>), typeof(MainWindow), new PropertyMetadata(null));

        List<ObservableCollection<PieSegmentModel>> collectionList = new List<ObservableCollection<PieSegmentModel>>();
        public MainWindow()
        {
            InitializeComponent();

            PieSegmentModels = new ObservableCollection<PieSegmentModel>();
            var collection1 = new ObservableCollection<PieSegmentModel>();
            collection1.Add(new PieSegmentModel { Name = "一", Value = 10 });
            collection1.Add(new PieSegmentModel { Name = "二", Value = 20 });
            collection1.Add(new PieSegmentModel { Name = "三", Value = 25 });
            collection1.Add(new PieSegmentModel { Name = "四", Value = 45 });
            var collection2 = new ObservableCollection<PieSegmentModel>();
            collection2.Add(new PieSegmentModel { Name = "一", Value = 30 });
            collection2.Add(new PieSegmentModel { Name = "二", Value = 15 });
            collection2.Add(new PieSegmentModel { Name = "三", Value = 10 });
            collection2.Add(new PieSegmentModel { Name = "四", Value = 55 });
            collectionList.AddRange(new[] { collection1, collection2 });

            PieSegmentModels = collectionList[0];
        }
        bool isRefresh = false;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!isRefresh)
                PieSegmentModels = collectionList[1];
            else
                PieSegmentModels = collectionList[0];
            isRefresh = !isRefresh;

        }
    }
}

到此這篇關(guān)于WPF仿LiveCharts實現(xiàn)餅圖的繪制的文章就介紹到這了,更多相關(guān)WPF餅圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#驗證控件validator的簡單使用

    C#驗證控件validator的簡單使用

    這篇文章主要介紹了C#驗證控件validator的簡單使用方法和示例,十分的簡單實用,有需要的小伙伴可以參考下。
    2015-06-06
  • C#語言async?await之迭代器工作原理示例解析

    C#語言async?await之迭代器工作原理示例解析

    這篇文章主要為大家介紹了C#語言async?await之迭代器工作原理示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-05-05
  • C#安裝OpenCvSharp4的實現(xiàn)步驟

    C#安裝OpenCvSharp4的實現(xiàn)步驟

    OpenCv是一款開源的圖像處理庫,本文就介紹了C#安裝OpenCvSharp4的實現(xiàn)步驟,具有一定的參考價值,感興趣的可以了解一下
    2022-05-05
  • C# 基礎(chǔ)入門--注釋

    C# 基礎(chǔ)入門--注釋

    本文主要介紹了C#中注釋的相關(guān)知識,具有很好的參考價值,下面跟著小編一起來看下吧
    2017-03-03
  • WinForm判斷關(guān)閉事件來源于用戶點擊右上角“關(guān)閉”按鈕的方法

    WinForm判斷關(guān)閉事件來源于用戶點擊右上角“關(guān)閉”按鈕的方法

    這篇文章主要介紹了WinForm判斷關(guān)閉事件來源于用戶點擊右上角“關(guān)閉”按鈕的方法,涉及C#針對WinForm事件的判定技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • vs2022程序打包文檔教程圖文詳解

    vs2022程序打包文檔教程圖文詳解

    這篇文章主要介紹了vs2022程序打包文檔教程,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-10-10
  • C# 實現(xiàn)微信自定義分享的示例代碼

    C# 實現(xiàn)微信自定義分享的示例代碼

    這篇文章主要介紹了C# 實現(xiàn)微信自定義分享的示例代碼,文中通過代碼示例給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作有一定的幫助,感興趣的同學(xué)可以自己動手嘗試一下
    2024-02-02
  • DevExpress GridView自動滾動效果

    DevExpress GridView自動滾動效果

    這篇文章主要為大家詳細介紹了DevExpress GridView自動滾動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • C#?模式匹配完全指南

    C#?模式匹配完全指南

    模式匹配是一種高端的使用機制,它允許程序員在開發(fā)的時候以對象的類型作為條件篩選和分情況處理的一種手段,本文給大家介紹C#?模式匹配完全指南,感興趣的朋友跟隨小編一起看看吧
    2022-03-03
  • C#實現(xiàn)老板鍵功能的代碼

    C#實現(xiàn)老板鍵功能的代碼

    最近在做項目中遇到需要增加個老板鍵功能,找一慣的方式,開始從網(wǎng)絡(luò)下手尋找: 關(guān)鍵字類似”C# 老板鍵“,一搜,一堆又一堆,然而出來的代碼大多數(shù)都不是太合適,下面給大家分享下自己的解決方案已經(jīng)一個網(wǎng)友的解決方案,有需要的小伙伴可以參考下。
    2015-05-05

最新評論

黔南| 四平市| 蒙山县| 齐河县| 那曲县| 巫山县| 民县| 永泰县| 吉木萨尔县| 海门市| 徐汇区| 彰化县| 延长县| 太湖县| 光泽县| 郎溪县| 关岭| 乐山市| 温州市| 汾阳市| 玛多县| 金昌市| 临武县| 百色市| 宜黄县| 瑞安市| 鄂州市| 利川市| 张家川| 女性| 太湖县| 龙南县| 延津县| 黄大仙区| 铅山县| 彭州市| 呈贡县| 军事| 公安县| 上饶市| 葫芦岛市|