WPF用SkewTransform画3D柱状图

SkewTransform主要是对控件实现一种2-D扭曲,具体内容可以查看以下链接: http://msdn.microsoft.com/zh-cn/library/system.windows.media.skewtransform.aspx 从图中可以看到,3-D的柱状图呈现给人们的是三个面,所以,我们需要用三个Rectangle经过SkewTransform变换来呈现柱状图的3个面,并且三个面的颜色要相互协调,给
  

  SkewTransform主要是对控件实现一种2-D扭曲,具体内容可以查看以下链接:

  http://msdn.microsoft.com/zh-cn/library/system.windows.media.skewtransform.aspx

  从图中可以看到,3-D的柱状图呈现给人们的是三个面,所以,我们需要用三个Rectangle经过SkewTransform变换来呈现柱状图的3个面,并且三个面的颜色要相互协调,给人一种立体的感觉。首先,新建一个WPF窗体,窗体上放置一个Canvas。

<Window x:Class="_3DHistogram.Window1"
    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>

  将各种已配好的颜色方案放在数组里,

private Color[,] colorsSolution = new Color[12, 3]
        {
           {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柱状图的更多相关文章

  1. 3-Highcharts 3D图之3D柱状图分组叠堆3D图

    <!DOCTYPE> <html lang='en'> <head> <title>3-Highcharts 3D图之3D柱状图分组叠堆3D图</ ...

  2. 2-Highcharts 3D图之3D柱状图带可调试倾斜角度

    <!DOCTYPE> <html lang='en'> <head> <title>2-Highcharts 3D图之3D柱状图带可调试倾斜角度< ...

  3. 1-Highcharts 3D图之普通3D柱状图与带空值

    <!DOCTYPE> <html lang='en'> <head> <title>1-Highcharts 3D图之普通3D柱状图与带空值</t ...

  4. WPF 图片浏览 伪3D效果

    原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...

  5. 利用WPF建立自己的3d gis软件(非axhost方式)(十二)SDK中的导航系统

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(十二)SDK中的导航系统 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew ...

  6. 利用WPF建立自己的3d gis软件(非axhost方式)(十三)万能的用户层接口,(强大的WPF)

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(十三)万能的用户层接口,(强大的WPF) 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt ...

  7. 利用WPF建立自己的3d gis软件(非axhost方式)(十一)SDK中的动画系统

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(十一)SDK中的动画系统 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew ...

  8. WPF动态加载3D 放大-旋转-平移

    原文:WPF动态加载3D 放大-旋转-平移 WavefrontObjLoader.cs 第二步:ModelVisual3DWithName.cs public class ModelVisual3DW ...

  9. extjs+amcharts生成3D柱状图和数据表格使用总结

    废话不多说,使用extjs+amcharts创建3d柱状图和数据表实例,如下: 1.首先定义一个数据模型 Ext.define("cacheHijack", { extend : ...

随机推荐

  1. 写给C语言新手的话

    首先声明啊,写这个是因为一些加我QQ的朋友问我学习经验,我才写的. 另外,如果是二级党,那么请用谭浩强老师的书.然后你就可以不用看了.倒不是有偏见,而是我写的这个东西,根本不是为了考试,而是为了和新手 ...

  2. Delphi的VMT的结构图,很清楚

    Every Delphi class is defined internally by its vmt—​its virtual-method table. The vmt contains a li ...

  3. 运行Dos命令并得到dos的输出文本(使用管道函数CreatePipe和PeekNamedPipe)

    function RunDOS(const CommandLine: string): string;var  HRead, HWrite: THandle;  StartInfo: TStartup ...

  4. NetBSD是个开源到源码的系统

    How to get NetBSD NetBSD is an Open Source operating system, and as such it is freely available for ...

  5. git版本号回滚

    先说今天遇到的问题,看到一个config.php的配置文件一直在改动的状态下,可是和远程的config.php是不一致的,我不须要提交它,可是看它在 modified的状态下,非常不爽.想删除它.gi ...

  6. C++不确定行为

    一个简单的程序引发了一块让人纠结的领域,也许强调编程规范的重要性也在这把.规范了就easy避免一些问题. 程序是这种 int Change(int& a) { a = 4; return a; ...

  7. 24位和8位BMP图片保存纯C代码

    BMP图片大家都知道,可以通过查看BMP图片结构使用纯C就可以打开,编辑,处理,保存图片.非常方便使用. 具体BMP结构可以参考:wingdi.h头文件.今天主要在进行删减代码,需要把多余的代码删除, ...

  8. OCA读书笔记(11) - 实现Oracle数据库审计

    11 Implementing Oracle Database Auditing 描述DBA对于安全和审计的职责使能标准的数据库审计安全审计选项查看审计信息维护审计路径 最小权限原则只在计算机上安装所 ...

  9. 安装Oracle JDK 7.0与8.0 for Mac OS X后Eclipse启动报错的解决之道

    启动 Eclipse 时,直接报错The JVM shared library "/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Cont ...

  10. uva :10123 - No Tipping(dfs + 几何力矩 )

    option=com_onlinejudge&Itemid=8&page=show_problem&category=109&problem=1064&mosm ...