12,069,536 members (65,002 online)
Add your own
alternative version

71.3K views
1.8K downloads
28 bookmarked
Posted

# Graphi - The Line Graph Component

, 1 Jun 2004
 Rate this:
Please Sign up or sign in to vote.
Displays a line graph for statistics using Enum.

## Introduction

Graphs can be very useful in Windows-based applications for pictorially displaying information and statistics. There are a number of tools that will allow you to create graphs for display within your applications. However, it isn't always feasible to purchase licenses for these tools, especially if the application is relatively simple or is constrained by a low budget. In this article, we'll focus on creating line point graphs using the Microsoft .NET Framework. This will involve using classes in the `System.Drawing` namespace. The component uses GDI+ that provides considerable support for transforming between different coordinate systems.

My objective is to display a line graph for the statistics on sales history, sales forecast, percentage of utilization for a resource … etc., for the year/quarter/six months based on hashtable values set from the WinForm during runtime. The user can set the X & Y axis scale during the design time. The X axis scale is designed to hold the scale by month wise for the first quarter, second quarter, third quarter, fourth quarter, first six months, last six months & year. The Y axis scale is designed to hold the growth rate based on the ranges from 0-100 [multiples of 10], 0-200 [multiples of 50], 0-200 [multiples of 25]. The below is the code that lists the enumeration constants in the property window for the component.

```public enum XAxisScale {
FirstQuarter = 0,
SecondQuarter = 1,
ThirdQuarter = 2,
FourthQuarter=3,
FirstSixMonths=4,
SecondSixMonths=5,
Year=6 }

public XAxisScale xAxisDrawingScale;
public XAxisScale XAxisScaleStyle
{
get { return xAxisDrawingScale;}
set { xAxisDrawingScale=value; }
}```

You can download the source code from the link provided above. Just drag and drop the component in your form and then set its X [`XAxisScaleStyle`] and Y [`YAxisScaleStyle`] axis scale using the `enum` listed in the property window as a drop down. After setting the scale, set the hash table values as provided below to the `xValues` property. That’s it. Have fun.

```Hashtable hTable = new Hashtable();

hTable.Add("JAN","25");
hTable.Add("fEB","100");
hTable.Add("MAR","125");
hTable.Add("APR","150");
hTable.Add("MAY","60");
hTable.Add("JUN","80");
hTable.Add("JUL","90");
hTable.Add("AUG","75");
hTable.Add("SEP","40");
hTable.Add("OCT","30");
hTable.Add("NOV","85");
hTable.Add("DEC","110");

lineGraph1.XValues=hTable;```

## 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

 Web Developer India
No Biography provided

## Comments and Discussions

 First Prev Next
 doubt superda7-Mar-07 4:29 superda 7-Mar-07 4:29
 Free Graph Component Anonymous2-Jul-04 10:07 Anonymous 2-Jul-04 10:07
 Re: Free Graph Component Anonymous2-Jul-04 10:14 Anonymous 2-Jul-04 10:14
 Article is simple and good Manivannan.V2-Jun-04 21:59 Manivannan.V 2-Jun-04 21:59
 download missing... Lil`Buh2-Jun-04 9:13 Lil`Buh 2-Jun-04 9:13
 URL LoneRanger2-Jun-04 9:24 LoneRanger 2-Jun-04 9:24
 Sample Image? Eric Engler2-Jun-04 3:43 Eric Engler 2-Jun-04 3:43
 Re: Sample Image? rajeshvasan2-Jun-04 19:15 rajeshvasan 2-Jun-04 19:15
 Last Visit: 31-Dec-99 19:00     Last Update: 9-Feb-16 2:25 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160208.1 | Last Updated 2 Jun 2004
Article Copyright 2004 by rajeshvasan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid