C# 3D Charting

来源:互联网 发布:勇者盟约图腾升星数据 编辑:程序博客网 时间:2024/04/29 14:38

文章标题:C# 3D Charting
原 作 者:Vincent DUVERNET (No
原 出 处:CodeProject
发 布 者:loose_went
发布类型:翻译
发布日期:2005-10-18
今日浏览:7
总 浏 览:1056
下载代码:

介绍

  首先我要感谢CodeProject提供这么好的例子,还特别感谢代码的作者提供用户定制面板。

背景

如果你知道EBP products,你也许会记得它主界面上那很酷的3D等距图表。现在就让我们来实现它。所有代码均在Microsoft FxCop 1.32下验证过。

写这篇文章有点吃力,不象用法语写那么容易,英文不太好,呵呵。

使用代码

  代码最能说明问题,让我们来看一下:

// Object declaration

Nolme.WinForms.Chart m_chartSample1;
 
// Create object
this.m_chartSample1 = new Nolme.WinForms.Chart(this.components);
this.m_chartSample1.BackColor = System.Drawing.Color.Silver;
this.m_chartSample1.BottomMargin = 20;
this.m_chartSample1.ColumnFont = new System.Drawing.Font("Arial", 8F, 
                                     System.Drawing.FontStyle.Italic);
this.m_chartSample1.ColumnTitleFont = new System.Drawing.Font("Arial", 
                             10F, System.Drawing.FontStyle.Underline);
this.m_chartSample1.Curvature = 15;
this.m_chartSample1.DeltaDepth = 10;
this.m_chartSample1.DisplayHiddenSides = true;
this.m_chartSample1.DisplayTextOnColumns = true;
this.m_chartSample1.GradientMode = 
     System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal;
this.m_chartSample1.LeftMargin = 50;
this.m_chartSample1.LegendFont = new System.Drawing.Font("Arial", 
                                 11F, System.Drawing.FontStyle.Bold);
this.m_chartSample1.Location = new System.Drawing.Point(8, 8);
this.m_chartSample1.MainTitle = "Main title";
this.m_chartSample1.MainTitleFont = new System.Drawing.Font("Arial", 16F, 
       ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | 
         System.Drawing.FontStyle.Underline))));
this.m_chartSample1.MarginBetweenColumn = 20;
this.m_chartSample1.Name = "m_chartSample1";
this.m_chartSample1.RightMargin = 20;
this.m_chartSample1.Size = new System.Drawing.Size(456, 304);
this.m_chartSample1.TabIndex = 4;
this.m_chartSample1.TopMargin = 20;
this.m_chartSample1.VerticalAxisMaxValue = 10000;
this.m_chartSample1.VerticalAxisStep = 1000;

增加一列的代码:

ChartColumn column1 = m_chartSample1.AddColumn (1500, 210, 0, 500);

在一个新列中,每一个数字代表一个次值,如果你有很多个值,你可以通过一个数组来传递。

你可以象这样来设置列的标题:

column1.Title = "January";

其它象页边距、主标题等属性也可以更改。

关于图表中的图例,有两种选择,第一,我们可以把图例整合到当前的面板中,第二,再建一个独立的对象。主要的意图是当在同一个页面使用多个图表时,能够提供一个集中在一起的图例。

总而言之,一个Chart( CustomPanel继承而来)包含一个或多个CharColumn。一个ChartLegendCharLegendItem组成。在CharColumn中有跟次值同样多的CharLegendItem

有趣的地方

  我已经使代码尽量简单,以便每个人都能读懂并升级它。

原创粉丝点击