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 : ...
随机推荐
- C++ delete 和 delete []
C++ delete 和 delete [] 简单结论: new delete new [] delete [] 文章 : 对 delete [] 的声明 void operator delete ...
- Qt4在linux下的安装
1.下载SDK ftp://ftp.informatik.hu-berlin.de/pub/Mirrors/ftp.troll.no/QT/qtsdk/qt-sdk-linux-x86-opensou ...
- 第二章 IoC Setter注入
Setter注入又称为属性注入.是通过属性的setXXX()方法来注入Bean的属性值或依赖对象.由于Setter注入具有可选择性和灵活性高的优点,因此Setter注入是实际应用中最常用的注入方式. ...
- Hide C# winform App Window When Started by Task Scheduler
To make a Scheduled Task run in the background, change the User running the task to "SYSTEM&quo ...
- CorePlot学习
阅读这篇文章,指出它在国外 原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview 强烈推荐阅读该 ...
- How a C++ compiler implements exception handling
Introduction One of the revolutionary features of C++ over traditional languages is its support for ...
- [每日一题] 11gOCP 1z0-052 :2013-09-5 runInstaller oracle of no swap
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11186995 正确答案:A 我们先来看下面这张截图,这是我在安装Oracle 11.2.0 ...
- poj3468 A Simple Problem with Integers(线段树模板 功能:区间增减,区间求和)
转载请注明出处:http://blog.csdn.net/u012860063 Description You have N integers, A1, A2, ... , AN. You need ...
- MVC之国际化
MVC之国际化 前言 在项目中遇到国际化语言的问题是常有的事情,之前在做关于MVC国际化语言时,刚开始打算全部利用AngularJS来实现,但是渐渐发现对于页面Title难以去控制其语言转换,于是对于 ...
- hdu 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)
http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序.问funny函数调用了多少次. 我们定义数组为所求 ...