Click here to Skip to main content
Click here to Skip to main content
Go to top

3D Bar Chart

, 19 May 2003
Rate this:
Please Sign up or sign in to vote.
Converting a 2D chart into a 3D chart

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

Share

About the Author

MJDamron
Software Developer
United States United States
I enjoy messing with application development and some Web development technologies. Right now I work in Virginia as a contractor to the government.
 
I am a Microsoft Cert. Professional and I got my 4 year BS degree.
 
See web site for resume and other code samples.

Comments and Discussions

 
GeneralGreat job! PinmemberJohannesM3-Jul-07 1:13 
Generallmd Pinmemberkurnikov11-Apr-07 6:35 
Generalgood Pinmemberjabby30-May-05 18:22 
GeneralA Better 3D UI PinmemberMJDamron23-May-03 1:32 
GeneralRe: A Better 3D UI Pinmemberprrusa9-Jun-05 15:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 20 May 2003
Article Copyright 2003 by MJDamron
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid