ARTICLE

Creating a Pie Chart on fly with VB.NET

Posted by Jigar Desai Articles | Visual Basic 2010 May 14, 2004
Dot net framework provides strong support for creating graphics with GDI+. Developing graphics application was never that much easier in past.
Download Files:
 
Reader Level:

Dot net framework provides strong support for creating graphics with GDI+. Developing graphics application was never that much easier in past.

You must have tried to create bar chart on your web site with dirty html or pie chart with third party components. In this article I am going to demonstrate GDI+ capabilities by creating component which can create a pie chart on fly for your web pages or for your windows application.

Pie Chart component is made up of two classes chartData class which encapsulates and  creates various data for creating pie chart and utChart class which contain method which returns stream object. Both of these classes are under namespace utCharting.

chartData:

Data required for creating chart is array of names and Vals which has to be distributed through pie. In new method of this class we take inputs as array of names and values , and using those values we have generated properties which describe percent values for each elements, similarly we determined span of pie for each elements by multiplying fraction of each element with 360 ( circle has 360 degree) and we obtained start angle for each elements by adding up span in loop.

utChart: 

T
his class has one method(getpiechart) which returns stream object which contains pie chart Image in gif formate, this method require inputs as chartdata object and integer object for diameter of pie chart.

We used fillpie method of graphics object to generate pie for all elements, most of the code is for determining size of string to be printed on image and determining size of image, to be created in memory. 

Attached: utCharting.vb , utCharting.dll.

How to use this component.

Sample shows aspx page which utilizes charting component, for that copy utcharting.dll to your bin directory of web server and copy createPieChar.aspx to you rootdirectory.

Our aspx page does following things:

  • Collects names, values and pie size data from query string or form.
  • Converts names in to string array.
  • Converts values into single array.
  • Converts piesize into integer. 
  1. Creates instance of chartdata using names and values array.
  2. Creates instance of utChart.
  3. Gets stream object from getPiechart method of utChart.
  4. Sets contenttype of page to "image.gif".
  5. Passes on stream object to browser.

Attached: createPieChart.dll.

Summary.

Although this sample is elementary, you can extend functionality by changing utchart class, one of things I missed is error handling and ways to make code work faster, you can also add barchart creation to this component. Or make 3D pie chart or cut out chart which shows chosen pie out of circle.

share this article :
post comment
 

It seems like You have never used RapidShare,

The provided Link is working perfectly fine..., I re-tested it just now.

http://rapidshare.com/files/49040737/Pie2.zip.html

Once you click the link it takes you to a web page....scroll down to the bottom and then click the free Button, after that probably there could be a wait for a minute, and if there is any wait then you see a count down timer..then it would show you some twisted Alpha numeric characters...once you enter the Alphanumeric characters correctly in the text box provided...you would get the download button.

But you won't have to go thru all this hastles if you have a premium rapidshare account.

 

I have now copied the zip to my Hobby site @...

http://patelplanet.com/Pie2.zip

 

Cheers

-Shrimant-

Posted by sh patel Sep 12, 2007

There is no zip file at the link

Posted by Patrick Rygiel Aug 17, 2007
Posted by sh patel Aug 14, 2007

http://rapidshare.com/files/49040737/Pie2.zip.html

The above is the Download link for the Modified code to work with .net 2.0 VS 2005

-Shrimant Patel-

 

Posted by sh patel Aug 14, 2007

No download avilable for this code.............. How can u post such things on the web

Posted by Rulian Mar 11, 2007
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor