WPF用SkewTransform画3D柱状图
WPF用SkewTransform画3D柱状图
SkewTransform主要是对控件实现一种2-D扭曲,具体内容可以查看以下链接:
http://msdn.microsoft.com/zh-cn/library/system.windows.media.skewtransform.aspx
从图中可以看到,3-D的柱状图呈现给人们的是三个面,所以,我们需要用三个Rectangle经过SkewTransform变换来呈现柱状图的3个面,并且三个面的颜色要相互协调,给人一种立体的感觉。首先,新建一个WPF窗体,窗体上放置一个Canvas。
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="800" WindowStartupLocation="CenterScreen">
<Canvas x:Name="PicBox">
</Canvas>
</Window>
将各种已配好的颜色方案放在数组里,
{
{Color.FromRgb(246,188,16),Color.FromRgb(194,153,11),Color.FromRgb(158,123,3)},
{Color.FromRgb(175,216,248),Color.FromRgb(135,173,196),Color.FromRgb(111,139,161)},
{Color.FromRgb(215,69,70),Color.FromRgb(167,55,54),Color.FromRgb(138,44,44)},
{Color.FromRgb(140,186,0),Color.FromRgb(112,147,1),Color.FromRgb(92,121,2)},
{Color.FromRgb(253,143,68),Color.FromRgb(200,114,55),Color.FromRgb(165,95,76)},
{Color.FromRgb(0,142,143),Color.FromRgb(0,113,113),Color.FromRgb(2,92,93)},
{Color.FromRgb(142,70,143),Color.FromRgb(117,56,116),Color.FromRgb(88,46,90)},
{Color.FromRgb(90,133,41),Color.FromRgb(70,107,30),Color.FromRgb(58,87,23)},
{Color.FromRgb(178,170,21),Color.FromRgb(142,133,0),Color.FromRgb(115,108,2)},
{Color.FromRgb(1,141,216),Color.FromRgb(3,112,175),Color.FromRgb(1,92,137)},
{Color.FromRgb(158,9,13),Color.FromRgb(130,7,10),Color.FromRgb(101,5,7)},
{Color.FromRgb(161,134,189),Color.FromRgb(127,105,151),Color.FromRgb(107,86,125)}
};
编写画单个柱状图的方法,函数根据提供的宽高以及颜色方案绘制相应的柱状图,
public StackPanel Draw3DHitsgram(Double width, Double height, int colorSolutionIndex)
{
StackPanel sp = new StackPanel()
{
Orientation = Orientation.Horizontal,
Height = height + width/3,
Width = width/3*4
};
Rectangle rect1 = new Rectangle()
{
Fill = new SolidColorBrush(colorsSolution[colorSolutionIndex, 0]),
Width = width,
Height = height,
VerticalAlignment = VerticalAlignment.Bottom
};
sp.Children.Add(rect1);
Rectangle rect2 = new Rectangle()
{
Fill = new SolidColorBrush(colorsSolution[colorSolutionIndex, 1]),
Width = width,
Height = width/3,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(-width/3*2, 0, 0, 0),
RenderTransform = new SkewTransform(-45, 0, 0, 0)
};
sp.Children.Add(rect2);
Rectangle rect3 = new Rectangle()
{
Fill = new SolidColorBrush(colorsSolution[colorSolutionIndex, 2]),
Width = width/3,
Height = height,
VerticalAlignment = VerticalAlignment.Bottom,
Margin = new Thickness(-width/3, 0, 0, 0),
RenderTransform = new SkewTransform(0, -45, 0, 0)
};
sp.Children.Add(rect3);
return sp;
}
在窗体的构造函数中用Random生成随机的宽和高,调用上面的函数,将绘制的柱状图添加至Canvas
public Window1()
{
InitializeComponent();
Random r = new Random();
for (int i = 0; i < 12; i++)
{
StackPanel sp = Draw3DHitsgram((Double)(r.Next(20, 50)), (Double)(r.Next(40, 200)), i);
Canvas.SetLeft(sp, 20 + 70 * i);
Canvas.SetTop(sp, 250 - sp.Height);
this.PicBox.Children.Add(sp);
}
}
本文来自junwillday的博客,原文地址:http://blog.csdn.net/junwillday/article/details/7347894
WPF用SkewTransform画3D柱状图的更多相关文章
- 3-Highcharts 3D图之3D柱状图分组叠堆3D图
<!DOCTYPE> <html lang='en'> <head> <title>3-Highcharts 3D图之3D柱状图分组叠堆3D图</ ...
- 2-Highcharts 3D图之3D柱状图带可调试倾斜角度
<!DOCTYPE> <html lang='en'> <head> <title>2-Highcharts 3D图之3D柱状图带可调试倾斜角度< ...
- 1-Highcharts 3D图之普通3D柱状图与带空值
<!DOCTYPE> <html lang='en'> <head> <title>1-Highcharts 3D图之普通3D柱状图与带空值</t ...
- WPF 图片浏览 伪3D效果
原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...
- 利用WPF建立自己的3d gis软件(非axhost方式)(十二)SDK中的导航系统
原文:利用WPF建立自己的3d gis软件(非axhost方式)(十二)SDK中的导航系统 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew ...
- 利用WPF建立自己的3d gis软件(非axhost方式)(十三)万能的用户层接口,(强大的WPF)
原文:利用WPF建立自己的3d gis软件(非axhost方式)(十三)万能的用户层接口,(强大的WPF) 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt ...
- 利用WPF建立自己的3d gis软件(非axhost方式)(十一)SDK中的动画系统
原文:利用WPF建立自己的3d gis软件(非axhost方式)(十一)SDK中的动画系统 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew ...
- WPF动态加载3D 放大-旋转-平移
原文:WPF动态加载3D 放大-旋转-平移 WavefrontObjLoader.cs 第二步:ModelVisual3DWithName.cs public class ModelVisual3DW ...
- extjs+amcharts生成3D柱状图和数据表格使用总结
废话不多说,使用extjs+amcharts创建3d柱状图和数据表实例,如下: 1.首先定义一个数据模型 Ext.define("cacheHijack", { extend : ...
随机推荐
- TCP_NODELAY详解
在网络拥塞控制领域,我们知道有一个非常有名的算法叫做Nagle算法(Nagle algorithm),这是使用它的发明人John Nagle的名字来命名的,John Nagle在1984年首次用这个算 ...
- 参加2013中国软件开发者大会(SDCC)会,听软件开发趋势
1.SDCC 盛大召开的会议,既然参加了,就写篇博客记一下. 2.蒋公子 首先向大会主席台走来的是csdn老大...... 额,好像不是走过来的.蒋涛采用了个特殊的上台方式呢~ ...
- hao947 : Mybatis resultMap配置插入和主键自增返回 : 好947
映射配置文件 好947 <!-- type:映射实体类的数据类型 id:resultMap的唯一标识 --> <resultMap type="person" ...
- centos7里默认python升级到2.7.11
CentOS镜像使用帮助 http://mirrors.163.com/.help/centos.html 安装gcc yum install gcc* openssl openssl-devel ...
- Mysql自增主键ID重新排序方法详解
Mysql数据库表的自增主键ID号乱了,需要重新排列. 原理:删除原有的自增ID,重新建立新的自增ID. 1,删除原有主键: ALTER TABLE `table_name` DROP `id`; 2 ...
- 使用PageHeap.EXE或GFlags.EXE检查内存越界错误
必先利其器之一:使用PageHeap.EXE或GFlags.EXE检查内存越界错误 Article last modified on 2002-6-3 ------------------------ ...
- WinDBG 技巧:如何生成Dump 文件(.dump 命令)
程序崩溃(crash)的时候, 为了以后能够调试分析问题, 可以使用WinDBG要把当时程序内存空间数据都保存下来,生成的文件称为dump 文件. 步骤: 1) 打开WinDBG并将之Attach 到 ...
- NEU 1173: 这是物理学的奇迹!! 分解质数
1173: 这是物理学的奇迹!! 题目描述 goagain在做物理电学实验时需要一个2Ω的电阻,但是他发现他的实验台上只剩下了3Ω,4Ω,5Ω,6Ω的电阻若干,于是goagain把两个4Ω的电阻并联起 ...
- Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Fai ...
- codeforces 598B Queries on a String
题目链接:http://codeforces.com/problemset/problem/598/B 题目分类:字符串 题意:给定一个串,然后n次旋转,每次给l,r,k,表示区间l到r的字符进行k次 ...