Click here to Skip to main content
6,596,602 members and growing! (21,178 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate

3D Bar Chart

By MJDamron

Converting a 2D chart into a 3D chart
C#, Windows, .NET 1.0, Visual Studio, Dev
Posted:19 May 2003
Views:79,065
Bookmarked:37 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 4.04 Rating: 3.16 out of 5
3 votes, 15.8%
1
4 votes, 21.1%
2
3 votes, 15.8%
3
3 votes, 15.8%
4
6 votes, 31.6%
5

Sample screenshot

Introduction

Currently, l am in Virginia. Cramped up in this tiny nom with my old laptop. I only dare to install Windows 98 on it - which means I only had the .Net Framework to work with. A week ago at work, I noticed my 3D Pie Chart had been published I soon ventured out to see how difficult it would be to do a 3D bar chart.

I did some test projects which are available above. I took an old VS.NET project and stripped it down so I could easily use it as a template. The projects' images or charts looked sweet using my high performance laptop (kidding). I hope they look Ok on a good monitor. (I only had a temporary job, so I�m stuck with my laptop.) I was left to using the good old command line and Notepad.

After adding the .NET directory to the PATH, I ran the MAKE batch file to build the template - which basically consisted of a form and a button.

Creating the graphs

I could have put some Image or Picture control and built the graph in memory (Bitmap) as I did in the 3D Pie chart article. It was just for a demonstration so all I needed was a device context (DC). The 3D illustration for the bar chart didn't look as effective as the pie chart. Maybe it is a result for my decision to drop the white background.

Anyway, to create a Graphics object to use the form's DC you use the FromHwnd method not FromHdc. An HWnd is a window handle and is provided as a property of a form.

The Graphics.FillPolygon method takes an array of Point objects and a brush. Remember that (X,Y) position or coordinates(0,0) is the top left corner of the client area of the window.

This demo draws ten bars with random depths or heights of individual bars. No legend information was designed into the demonstration.

The 3D illustration can be achieved by drawing a series of polygons (referred to as slices) with the hatched brush. Every slice is a pixel apart from the other. Each bar is 5 pixels apart.

Once I had the four desired points of my polygon (a rhombus) I drew the bottom slice, decremented the Y values of each Point in the array (which in turn, drew the slices in an upwards fashion), and drew the final slice with the solid brush. In the code, I create a new hatched brush on every slice � this is not necessary but I didn�t want to fix it.

Pressing the Run button again, clears the previous drawing and begins anew. Notice if you minimize the window the drawing is also erased.

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

MJDamron


Member
I enjoy messing with application development and some Web development technologies. Unfortunatly at this time, I have been unable to do as much with Web services as I would like. I would love to get a good job doing software development full time... Right now I work in Virginia as a contractor to the US Navy.

I am a Microsoft Cert. Professional and I got my 4 year BS degree.
Occupation: Web Developer
Location: United States United States

Other popular GDI+ articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralGreat job! PinmemberJohannesM2:13 3 Jul '07  
Generallmd Pinmemberkurnikov7:35 11 Apr '07  
Generalgood Pinmemberjabby19:22 30 May '05  
GeneralA Better 3D UI PinmemberMJDamron2:32 23 May '03  
GeneralRe: A Better 3D UI Pinmemberprrusa16:35 9 Jun '05  

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

PermaLink | Privacy | Terms of Use
Last Updated: 19 May 2003
Editor: Chris Maunder
Copyright 2003 by MJDamron
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project