WPF实现特殊统计图
原文:WPF实现特殊统计图

效果图:

ActiveFunItem.xaml代码:

<UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunItem"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" mc:Ignorable="d" d:DesignHeight="74" d:DesignWidth="50"><Grid><Grid.RowDefinitions><RowDefinition Height="{Binding ItemWidth}"></RowDefinition><RowDefinition Height="24"></RowDefinition></Grid.RowDefinitions><Border Width="{Binding ItemWidth}" Height="{Binding ItemWidth}" Background="{Binding FillColor}" BorderBrush="{Binding BorderColor}" BorderThickness="2" CornerRadius="{Binding ItemWidthHalf}" ><Border.ToolTip><ToolTip><ToolTip.Template><ControlTemplate><Border Background="#88333333" CornerRadius="4"><TextBlock Margin="5" Foreground="#f2f2f2" Text="{Binding FunName}"></TextBlock></Border></ControlTemplate></ToolTip.Template></ToolTip></Border.ToolTip><Image Width="{Binding IconWidth}" Height="{Binding IconWidth}" Stretch="Fill" Source="{Binding Image}" VerticalAlignment="Center" HorizontalAlignment="Center"></Image></Border><StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center"><TextBlock Text="{Binding Count}" Foreground="#008bf1" FontSize="20" VerticalAlignment="Center"></TextBlock><TextBlock Text="次" Foreground="#008bf1" FontSize="20" VerticalAlignment="Center"></TextBlock></StackPanel></Grid>
</UserControl>

View Code

ActiveFunItem.xaml.cs代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Navigation;
using System.Windows.Shapes;namespace SunCreate.Vipf.Client.UI
{/// <summary>/// 图标控件/// </summary>public partial class ActiveFunItem : UserControl, INotifyPropertyChanged{private Thickness _OriginalMargin;/// <summary>/// 初始Margin/// </summary>public Thickness OriginalMargin{get{return _OriginalMargin;}set{_OriginalMargin = value;OnPropertyChanged("OriginalMargin");}}private int _ItemWidth = 50;/// <summary>/// 圆宽度/// </summary>public int ItemWidth{get{return _ItemWidth;}set{_ItemWidth = value;OnPropertyChanged("ItemWidth");ItemWidthHalf = ItemWidth / 2;IconWidth = (int)(ItemWidth * 0.65);}}private int _ItemWidthHalf = 25;/// <summary>/// 圆宽度一半/// </summary>public int ItemWidthHalf{get{return _ItemWidthHalf;}set{_ItemWidthHalf = value;OnPropertyChanged("ItemWidthHalf");}}private int _IconWidth = 30;/// <summary>/// 图标宽度/// </summary>public int IconWidth{get{return _IconWidth;}set{_IconWidth = value;OnPropertyChanged("IconWidth");}}private SolidColorBrush _FillColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9848"));/// <summary>/// 填充颜色/// </summary>public SolidColorBrush FillColor{get{return _FillColor;}set{_FillColor = value;OnPropertyChanged("FillColor");}}private SolidColorBrush _BorderColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ed6900"));/// <summary>/// 边框颜色/// </summary>public SolidColorBrush BorderColor{get{return _BorderColor;}set{_BorderColor = value;OnPropertyChanged("BorderColor");}}private ImageSource _Image = new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-人脸分析.png", UriKind.RelativeOrAbsolute));/// <summary>/// 图标的图片/// </summary>public ImageSource Image{get { return _Image; }set{_Image = value;OnPropertyChanged("Image");}}private int _Count = 3600;/// <summary>/// 活跃次数/// </summary>public int Count{get{return _Count;}set{_Count = value;OnPropertyChanged("Count");}}private string _FunName;/// <summary>/// 功能名称/// </summary>public string FunName{get{return _FunName;}set{_FunName = value;OnPropertyChanged("FunName");}}public ActiveFunItem(){InitializeComponent();this.DataContext = this;}#region INotifyPropertyChanged接口public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged(string name){if (PropertyChanged != null){PropertyChanged(this, new PropertyChangedEventArgs(name));}}#endregion}
}

View Code

ActiveFunction.xaml代码:

<UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunction"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:SunCreate.Vipf.Client.UI"mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded"><Grid><Grid.RowDefinitions><RowDefinition Height="30"></RowDefinition><RowDefinition Height="1*"></RowDefinition></Grid.RowDefinitions><Border CornerRadius="5 5 0 0" Background="#368bf0"><StackPanel Orientation="Horizontal" Margin="10 0 0 0"><Image Width="14" Source="/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/面板-活跃功能.png"></Image><TextBlock Margin="10 0 0 0" Text="活跃功能" FontSize="14" Foreground="#fff" VerticalAlignment="Center"></TextBlock></StackPanel></Border><Border Grid.Row="1" CornerRadius="0 0 5 5" Background="#ffffff" BorderThickness="1 0 1 1" BorderBrush="#dddddd" SnapsToDevicePixels="True"><Grid><Viewbox x:Name="viewbox" Stretch="Fill" Height="260" Width="260"><Canvas Width="320" Height="320"><Grid><Grid Width="300" Height="300"><Grid.Background><ImageBrush Stretch="Fill" ImageSource="/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃总量.png"/></Grid.Background></Grid><Grid x:Name="container" Width="320" Height="320"><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="76,20,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="173,20,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="240,79,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="241,182,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="171,247,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="75,247,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="11,178,0,0"></local:ActiveFunItem><local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="12,82,0,0"></local:ActiveFunItem></Grid><TextBlock Text="{Binding Count}" FontSize="30" FontWeight="Bold" Foreground="#ff2121" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock></Grid></Canvas></Viewbox></Grid></Border></Grid>
</UserControl>

View Code

ActiveFunction.xaml.cs代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Navigation;
using System.Windows.Shapes;namespace SunCreate.Vipf.Client.UI
{/// <summary>/// 活跃功能/// </summary>public partial class ActiveFunction : UserControl, INotifyPropertyChanged{#region 字段属性/// <summary>/// 图标控件集合/// </summary>private List<ActiveFunItem> _list = new List<ActiveFunItem>();/// <summary>/// 图标背景颜色/// </summary>private SolidColorBrush[] _fillColorArr = new SolidColorBrush[8] {new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9848")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff211b")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00d235")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0"))};/// <summary>/// 图标背景边框颜色/// </summary>private SolidColorBrush[] _borderColorArr = new SolidColorBrush[8] {new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ed6900")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b40000")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00912b")),new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1"))};/// <summary>/// 图标大小/// </summary>private int[] _widthArr = new int[8] {90,80,70,60,55,50,45,40};/// <summary>/// 位置数组/// </summary>private int[] _posArr = new int[8] {3,0,6,2,7,4,1,5};/// <summary>/// 功能名称图标集合/// </summary>private Dictionary<string, ImageSource> _dictNameIcon = new Dictionary<string, ImageSource>();private int _Count;/// <summary>/// 活跃总量/// </summary>public int Count{get{return _Count;}set{_Count = value;OnPropertyChanged("Count");}}#endregionpublic ActiveFunction(){InitializeComponent();this.DataContext = this;this.Count = 21834; //活跃总量#region 功能名称图标集合(后期补充更多功能名称图标)_dictNameIcon.Add("车辆分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-车辆分析.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("行为分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-行为分析.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("结构化分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-结构化分析.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("历史视频", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-历史视频.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("人脸分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-人脸分析.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("实时视频", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-实时视频.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("视频巡查", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-视频巡查.png", UriKind.RelativeOrAbsolute)));_dictNameIcon.Add("资源申请", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-资源申请.png", UriKind.RelativeOrAbsolute)));#endregion#region 初始化控件int i = 0;foreach (ActiveFunItem item in container.Children){item.OriginalMargin = new Thickness(item.Margin.Left + 25, item.Margin.Top + 25, 0, 0);item.FillColor = _fillColorArr[i];item.BorderColor = _borderColorArr[i];_list.Add(item);i++;}#endregionStatistic();}#region 统计/// <summary>/// 统计/// </summary>public void Statistic(){#region 活跃功能活跃次数测试数据Dictionary<string, int> dict = new Dictionary<string, int>();dict.Add("人脸分析", 1223);dict.Add("行为分析", 239);dict.Add("结构化分析", 621);dict.Add("历史视频", 1520);dict.Add("实时视频", 523);dict.Add("车辆分析", 805);dict.Add("视频巡查", 89);dict.Add("资源申请", 363);#endregion#region 重新计算ActiveFunItem属性List<KeyValuePair<string, int>> _sortedList = dict.ToList();_sortedList.Sort((a, b) => b.Value - a.Value); //对统计数据排序for (int k = 0; k < _sortedList.Count; k++){KeyValuePair<string, int> keyValuePair = _sortedList[k];int index = _posArr[k];ActiveFunItem funItem = _list[index];funItem.ItemWidth = _widthArr[k];funItem.Margin = new Thickness(funItem.OriginalMargin.Left - funItem.ItemWidthHalf, funItem.OriginalMargin.Top - funItem.ItemWidthHalf, 0, 0);funItem.Count = keyValuePair.Value;funItem.FunName = keyValuePair.Key;if (_dictNameIcon.Keys.Contains(keyValuePair.Key)){funItem.Image = _dictNameIcon[keyValuePair.Key];}else{funItem.Image = null;}}#endregion}#endregion#region INotifyPropertyChanged接口public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged(string name){if (PropertyChanged != null){PropertyChanged(this, new PropertyChangedEventArgs(name));}}#endregion#region UserControl_Loadedprivate void UserControl_Loaded(object sender, RoutedEventArgs e){double h = this.ActualHeight - 32;double w = this.ActualHeight - 2;if (h < w){viewbox.Height = h;viewbox.Width = h;}else{viewbox.Height = w;viewbox.Width = w;}}#endregion}
}

View Code

posted on 2019-04-12 23:34 NET未来之路 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/10699321.html

WPF实现特殊统计图相关推荐

  1. WPF 实现扇形统计图

    扇形统计图 原文作者:ArcherSong 博客地址:https://www.cnblogs.com/ganbei/ 绘制一个扇形原理也是基于Canvas进行绘制; ArcSegment[1]绘制弧形 ...

  2. WPF实现统计图(饼图仿LiveCharts)

    WPF开发者QQ群: 340500857  | 微信群 -> 进入公众号主页 加入组织 欢迎转发.分享.点赞.在看,谢谢~. 01 - 效果预览 效果预览(更多效果请下载源码体验): 一.Pie ...

  3. 用WPF山寨折线图,抄?是狠狠的抄

    对于没有美术细胞的我来说,抄袭人家的设计或是创意是再平常不过的事,我承认这很无耻,如果在伟大"天朝"的教育体系下还可能升级为道德上的沦丧,毕竟人家搞个东西也不容易,可任务在身,只好 ...

  4. 看看这套WPF开源基础控件库:WPFDevelopers

    此项目包含了 微信公众号 < WPF开发者> 日常开发分享,欢迎Star. 运行环境 Visual Studio 2019,dotNet Framework 4.0 SDK 欢迎关注微信公 ...

  5. wpf 音频波形图_wpf波形图 - IT屋-程序员软件开发技术分享社区

    我正在使用.net WPF几何图形类来绘制波形图.我一直在使用矩阵变换将屏幕坐标空间转换为波形的坐标空间.一切都很好,而且跟踪窗口和缩放比例等非常简单.我什至可以使用逆变换来根据坐标空间计算鼠标位置. ...

  6. 新手用WPF山寨QQ管家7.6(三)

    由于一直忙工作,没有更新完博客,更可恨的是...在清理资料的时候不小心删除了之前自己做的各种效果的DEMO....好在项目中用到了大部分,也算有所保留,以后可不敢随便删东西了....太可怕了! 在 新 ...

  7. [Aaronyang]谈谈2015年AY对WPF全面技术总结40多篇WPF,炫到没朋友的AYUI来了

             原著:AY WPF博客- 把wpf推广出去,让那些鄙视的人说不 大家好! 我是AY,首先声明,我在做一件很枯燥的事情,我是个91后程序员,每天熬夜完成计划的过着下班后的生活. 那天有 ...

  8. C# 之 WPF 统计图表开发方案

    C# 之 WPF 统计图表开发文档 一.前言 二.环境配置 1.开发环境 2.加载 LiveCharts 库 3.添加必须的头文件 三.基础图形 1.柱状图(ColumnCharts) 2.饼状图(P ...

  9. 基于 WPF + Modern UI 的 公司OA小助手 开发总结

    前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个阶段的一个反思.人只有在总结的过程中才会发现自己的不足. 公司每天都要在OA系统上上班点击签到,下班点击签退 ...

最新文章

  1. tornado(七)
  2. HGST:中国将成为新云端运算大国
  3. linux下nginx启动停止重启控制脚本
  4. jQuery - 链(Chaining)
  5. Dubbo核心源码之SPI扩展
  6. android 相机功能修改,安卓用户又少了一项自由,Android 11不再支持更改默认相机程序...
  7. ZZULIOJ 1882: 蛤玮的魔法【数学】
  8. Centos7修改服务器密码
  9. 华为进不了美国,并不是贸易保护这么简单
  10. chrome手机版怎么扫描二维码_照片扫描仪软件手机版-照片扫描仪手机版官网版下载v3.2.0...
  11. Redis数据莫名其妙全部丢失
  12. python自动填表格_Windows下使用python3 + selenium实现网页自动填表功能
  13. 化妆行业网站建设方案
  14. 数字电子技术基础实验 实验一 门电路的逻辑功能及参数测试(含数据及思考题)
  15. 利用python爬取知乎评论_一个简单的python爬虫,爬取知乎
  16. RtspLiveServer一款支持rtsp协议流媒体服务器软件
  17. Markdown排版操作
  18. Spring Boot 实现接口的各种参数校验
  19. linux内核信号处理机制--do_signal函数讲解 (适用mips架构)
  20. 苹果以旧换新活动_苹果悄悄下调了设备回收价格 但影响大吗

热门文章

  1. linux切大文件为小文件,linux系统下分割大文件的方法
  2. 【动态规划笔记】01背包问题及优化
  3. Java .net 心得_我做英文站的心得-如何做好英文站 - 程序员日记 - 做人做技术【关注.NET和JAVA】...
  4. confluence 4.2 升级至 6.10.x 记录
  5. git修改本地仓库和远程仓库名称
  6. Protocol ‘https‘ not on whitelist ‘file,crypto‘ ——m3u8下载协议不在白名单,m3u8下载器推荐
  7. NYOJ77 - 开灯问题
  8. 如何将php里面的首行缩进_word首行缩进排版的三个技巧
  9. linux ssh客户端_Linux终端连接Linux服务器
  10. itunes备份包括哪些内容_企业形象策划包括哪些内容?