search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

C# Create a Piechart for the specified Hard Disk Drive Utilization


By Raj Cool...
Printer Friendly Version
View My Articles
14 Views
    

This application can be used to generate a piechart for the hard disk drive utilization. You can provide any drive as input and it will generate the output folder wise utilization. You can see the given output. The code is lengthy so I have provided individual pieces of the code functions.


The namespaces used:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using System.Data;

The structure used:

struct MyDirTotalSize
        {
            public string dirPath;
            public long totalSize;
            public int parent;
        }
struct MyAngleStruct { public string folderpath; public float myAngle; public long mySize; } The below function is responsible for the creating angle for each folder path: private void GeneratePieChartAngle(string path) { MyAngleStruct angStructObj; angStructObj.myAngle = 0; MyDirTotalSize eff; long opteller = 0, compsize = 0; int startingPoint = -1, startingPoint2; for (startingPoint2 = 0; startingPoint2 < SizeDir.Count; startingPoint2++) { eff = (MyDirTotalSize) (SizeDir[startingPoint2]); if (path != eff.dirPath) continue; compsize += eff.totalSize; angStructObj.folderpath = eff.dirPath; angStructObj.mySize = eff.totalSize; AngleS.Add(angStructObj); startingPoint = eff.parent; } foreach (MyDirTotalSize ef in SizeDir) { if (ef.dirPath.CompareTo(path) == 0 || startingPoint < 0) continue; if (!ef.dirPath.StartsWith(path)) continue; compsize += ef.totalSize; startingPoint2 = ef.parent; opteller += ef.totalSize; if (startingPoint2 > (startingPoint + 1)) continue; angStructObj.folderpath = ef.dirPath; angStructObj.mySize = opteller; AngleS.Add(angStructObj); opteller = 0; //ef.size; } startingPoint = AngleS.Count; for (startingPoint2 = 0; startingPoint2 < startingPoint; startingPoint2++) { angStructObj = (MyAngleStruct) (AngleS[startingPoint2]); AngleS.RemoveAt(startingPoint2); angStructObj.myAngle = (angStructObj.mySize/(float) compsize)*360; AngleS.Insert(startingPoint2, angStructObj); } } Get the total size of given directory folder: private void GetDirveDirTotalSize(string path, int index) { MyDirTotalSize total1, total2; DirectoryInfo[] dirs; DirectoryInfo dir = new DirectoryInfo(path); dirs = dir.GetDirectories(); foreach (DirectoryInfo run in dirs) { nAantalDirs = index + 1; GetDirveDirTotalSize(run.FullName, nAantalDirs); } total1.dirPath = path; long totalFileSizeInFolder=0; FileInfo[] files; DirectoryInfo file = new DirectoryInfo(path); files=file.GetFiles(); foreach(FileInfo run in files) totalFileSizeInFolder+=run.Length; total1.totalSize = totalFileSizeInFolder; total1.parent = index; SizeDir.Add(total1); total2 = (MyDirTotalSize) SizeDir[(SizeDir.Count - 1)]; nAantalDirs = total2.parent; } Draw the piechart angles from starting to ending position and you are done. private void DrawPitotal1romAngles() { float realAngle=0F; Random rnd = new Random(); Red=Green=Blue=0; pas.Clear(BackColor); foreach(MyAngleStruct total1 in AngleS) { pas.FillPie(brus,rRect,realAngle,total1.myAngle);realAngle+=total1.myAngle; //Generate random color for drawing int myRed = myGreen = myBlue = Random() % 250; brus.Color = System.Drawing.Color.FromArgb(myRed,myGreen,myBlue); } }


Output:







button
Article Discussion: C# : Create the piechart for the specified Hard Disk Drive Utilization
Raj Cool... posted at Saturday, December 06, 2008 2:57 AM
Original Article
 

http://210.245.85.167/hpa/programming/archive/2009/01/22/t-o-bi-u-xem-dung-l-ng-c-ng.aspx
Stella Pandian replied to Raj Cool... at Friday, April 03, 2009 5:14 AM

 

 

Its my complete article copied there. I will inform Rob about this.
Raj Cool... replied to Stella Pandian at Friday, April 03, 2009 10:26 PM
end of post