5,699,431 members and growing! (24,799 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Miscellaneous Controls     Intermediate

C# 3D Charting

By Vincent DUVERNET (Nolmë Informatique)

A simple article for easy charting.
C#, Windows, .NET 1.1, .NET, WinForms, GDI+, Visual Studio, VS.NET2003, Dev

Posted: 4 Oct 2005
Updated: 24 May 2006
Views: 89,081
Bookmarked: 159 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
50 votes for this Article.
Popularity: 7.52 Rating: 4.43 out of 5
3 votes, 6.0%
1
0 votes, 0.0%
2
3 votes, 6.0%
3
13 votes, 26.0%
4
31 votes, 62.0%
5

Introduction

I want to begin with a special thanks to CodeProject for providing so many useful samples, and thanks especially to the author of this article: Customizing the .NET Panel control.

Background

If you know about the EBP products, then you'll remember their main board with a simple but cool isometric 3D chart. So, let's do the same here. All the code has been verified under Microsoft FxCop 1.35.

I'm not very comfortable in writing articles even in French, so English isn't better ;p.

Using the code

Let's see the creation code:

// 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;

Adding a column to the chart is done with the following code:

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

Each number represents a sub-value in the new column. You can pass an integer array if you have more values.

You can set the column title like this:

column1.Title = "January";

Other attributes like the margins, main title, etc., can be changed.

There were two choices on the legend of the graph. We could either integrate the legend into the current panel, or make another independent object. The main intention is to provide a centralized unique legend if multiple charts are used on the same page.

To summarize, a Chart (derived from CustomPanel) contains one or more CharColumns. A ChartLegend is composed of CharLegendItems. There are as many CharLegendItems as sub-values in a CharColumn.

Points of interest

I've tried to make the code as simple as possible so that anyone can upgrade it.

Bug report

Nothing actually.

History

  • 2006-04-08
    • Thanks timbits214, changes have been done.
    • So, I've added a new mode for 'real time' rendering.
    • Chart.cs has a new method, ShiftLeft, to shift columns from one step to the left.
    • With these changes, ChartColumn integrates a default constructor and ResetValues.
  • 2006-03-31
    • The new version contains a new rendering mode: 3D with gradient.
    • Bug fixed: Left grid text starting at 0.
    • Bug fixed: Vertical axis auto-adjusts when min and max don't have the same digit numbers (100 and 1000, for example).
    • Bug fixed: Border drawings and optimization.
    • Bug fixed: Label on the column with negative values.
    • New function: DisplayBorders in ChartColumn.cs.
    • Some changes have been made in the function parameters list to support gradient drawing mode.
  • 2005-10-07
    • New version contains a new rendering mode. See the ChartRenderingMode enum.
    • Associated to this new mode, ChartCumulativeMode enum can define where a label on the column is placed.
    • Some changes have been made in the function parameters list.
  • 2005-10-08
    • Negative values are now managed.
    • The function AdjustVerticalAxis has been reviewed.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vincent DUVERNET (Nolmë Informatique)



Occupation: Web Developer
Location: France France

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 36 (Total in Forum: 36) (Refresh)FirstPrevNext
General3d chart plottingmemberFaysal1:16 26 Mar '08  
GeneralRe: 3d chart plottingmemberVincent DUVERNET (Nolmë Informatique)5:10 28 Mar '08  
GeneralRe: 3d chart plottingmemberFaysal16:08 28 Mar '08  
GeneralRe: 3d chart plottingmemberVincent DUVERNET (Nolmë Informatique)4:40 29 Mar '08  
GeneralWonderful !memberJulienV3:02 3 Sep '07  
Generallmdmemberkurnikov7:36 11 Apr '07  
GeneralRe: lmdmemberVincent DUVERNET (Nolmë Informatique)9:24 13 Apr '07  
GeneralAdding control to VS?membermikemohr8:30 3 Nov '06  
GeneralRe: Adding control to VS?memberVincent DUVERNET (Nolmë Informatique)12:30 3 Nov '06  
QuestionWhat about a web based solution?memberMarcus D7:22 18 Oct '06  
AnswerRe: What about a web based solution?memberVincent DUVERNET (Nolmë Informatique)8:16 18 Oct '06  
GeneralOne Suggessionmemberjayvardhanpatil23:48 28 Sep '06  
QuestionCoolmembertechno_adi21:14 29 Aug '06  
AnswerRe: CoolmemberVincent DUVERNET (Nolmë Informatique)22:09 29 Aug '06  
GeneralImpressive!memberDanilo Corallo4:16 20 Jul '06  
GeneralNice TrymemberSendilkumar.M19:27 24 May '06  
GeneralVery NicememberPaul Conrad17:53 24 May '06  
GeneralSave & PrintmemberChestah0:27 18 May '06  
GeneralRe: Save & PrintmemberVincent DUVERNET (Nolmë Informatique)1:26 18 May '06  
JokeRe: Save & PrintmemberChestah12:04 18 May '06  
Questionlicensing / usage querymemberSimonS6:18 11 Apr '06  
AnswerRe: licensing / usage querymemberVincent DUVERNET (Nolmë Informatique)8:04 11 Apr '06  
GeneralRe: licensing / usage querymemberSimonS8:15 11 Apr '06  
GeneralRe: licensing / usage querymemberVincent DUVERNET (Nolmë Informatique)8:38 11 Apr '06  
GeneralFlickeringmembertimbits21421:54 7 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 May 2006
Editor: Smitha Vijayan
Copyright 2005 by Vincent DUVERNET (Nolmë Informatique)
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project