Click here to Skip to main content
5,787,682 members and growing! (18,441 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Libraries » General     Beginner License: The Code Project Open License (CPOL)

Simple Column Chart Generator

By Diogo Arenhart

With this library it’s possible to generate some column chart images easily
C# (C# 1.0, C# 2.0, C# 3.0, C#), .NET (.NET, .NET 2.0)

Posted: 18 Jan 2008
Updated: 26 Jan 2008
Views: 10,910
Bookmarked: 35 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
12 votes for this Article.
Popularity: 4.89 Rating: 4.53 out of 5
0 votes, 0.0%
1
1 vote, 8.3%
2
1 vote, 8.3%
3
2 votes, 16.7%
4
8 votes, 66.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article
ForLogic

Introduction

This article shows how to generate some column chart images for your users on a easy way. You can simply give some arguments to the class library and receive back an image object, or directly save it on hard disk.

Will be shown in this article an example application, how to use the class library, the features implemented and the future enhancements. The image below is an example of column chart created using this class library.

img2.png

Building a library like this it´s not a so easy task, because the number of calcs you have to do to render the image grow up faster on the way you add new features. Making a library with just a few features also doesn’t make sense, cause you’ll probably have to re-implement it again all time you need to use it.

Searching on the Web it’s easy to find some good (great) chart generator libraries. Most of them you have to pay if you want to use without have access to source code.

The goal of this article is to share knowledge and give developers an alternative to create some simple column chart images. The image below is another example.

img5.png

The image below is a chart example using negative values.

001.png

The Demo Application

To easily understand the features of this library I have developed a demo application, that looks like the image below:

image005.jpg

With this demo application we can give some arguments to the engine and the image will be rendered just below (as you can see on the image). It’s important to say here not all the features and possibilities are avaiable at this demo application.

Inside the first group named “Column Chart Properties” we have the general chart properties, like image width, height, margins, etc. The second ant third groups are related to the columns values and descriptions. Through this groups you can remove and add new columns to the chart. Try it!

Library Features – How To Use It!

To let this project most flexible you can format the chart your way. There’s lots of combinations you can create, giving the charts other appearances. I’ll enumerate here some properties of the chart you can access and change. Most of this properties are self explained.

Chart Properties:

  • Width
  • Height
  • Image Background Color
  • Column Spacing
  • Margins
  • Depth
  • Value Format
  • Value Font (family, size and style)
  • Description Font (family, size and style)
  • Show Columns Values
  • Show Columns Descriptions
  • Show Guide Lines
  • Guide Lines Line Width
  • Guide Lines Font (family, size and style)
  • Guide Lines Values Format
  • Guide Lines Color
  • Guide Lines Text Color
  • Guide Lines Count
  • XY Line Color
  • XY Line Width
  • XY Text Color

We can create an instance of the chart object with just this code:

    ColumnChart chart = new ColumnChart();
    chart.Width = 250;
    chart.Height = 220;

Now we’ll have to add some columns. Below are the columns properties:

Columns Properties:

  • Fill Color
  • Value
  • Description

There are two ways to add columns. The first is using directly the Add method, adding new columns to the collection. The second way is passing a DataTable object to the SetDataSource method.

1st way:

    ColumnChartItem item1 = new ColumnChartItem(Color.DarkBlue, “any description”, 12);
    ColumnChartItem item2 = new ColumnChartItem(Color.DarkOrange, “test”, 15);
    ColumnChartItem item3 = new ColumnChartItem(Color.DarkGreen, “description”, 10);
    chart.Items.Add(item1);
    chart.Items.Add(item2);
    chart.Items.Add(item3);

2nd way:

    chart.SetDataSource(datatable, "valueColumn", "descriptionColumn");

Future Enhancements

Actually it’s not possible to group data columns. It’s a limitation of this version.

Also would be great if we have other types of chart, like line charts, pie charts, bar charts, etc.

Conclusion

This is a limited alternative to generate column charts, but can be used on simple tasks. It’s possible to share some knowledge with this little project, explaining how to use the library and giving access to the source code.

History

  • [26/Jan/2008] Bug fix and new features
    • Bug fix: System.DivideByZeroException reported by Vertexwahn.
    • New feature 1: Added property GuideLinesCount.
    • New feature 2: It's possible to add negative value columns.
  • [18/Jan/2008] Original version posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Diogo Arenhart



Occupation: Software Developer
Company: ForLogic Software
Location: Brazil Brazil

Other popular Libraries articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
GeneralVery NicememberPaul Conrad7:52 27 Jan '08  
GeneralSystem.DivideByZeroExceptionmemberVertexwahn12:50 23 Jan '08  
GeneralRe: System.DivideByZeroExceptionmemberDiogo Arenhart8:44 4 Feb '08  
GeneralNice projectmemberthompsons9:03 19 Jan '08  
GeneralVery nice ControlmemberAbhijit Jana21:27 18 Jan '08  
Generalexcellent!memberTheCardinal15:59 18 Jan '08  

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

PermaLink | Privacy | Terms of Use
Last Updated: 26 Jan 2008
Editor:
Copyright 2008 by Diogo Arenhart
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project