Click here to Skip to main content
6,630,901 members and growing! (19,919 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Controls     Intermediate

Simple Bar Chart for Pocket PC

By pablojag

Generate simple bar chart for Pocket PC.
C#, Windows, .NET CF, .NET, Visual Studio, Dev
Posted:16 Nov 2005
Views:31,219
Bookmarked:25 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 2.33 Rating: 3.33 out of 5
1 vote, 20.0%
1

2

3
2 votes, 40.0%
4
2 votes, 40.0%
5

Introduction

I recently had to generate a bar chart for a Pocket PC application. There are a lot of materials on the web on this issue, articles, freeware, etc., but I couldn't find anything that worked for a compact framework.

Some times as a developer I think why take so much time to solve something that some body has already done? Well this time it wasn't the case so, I decided to work around the problem myself.

Using the code

The application posted in this article contains a compact Windows Forms project written in C# with a single form with no controls. It takes in the Load event of the PocketBarGraph component and fills it with dummy data as you can see below. The rest is done through the component and the Paint event of that form. The trick here is to send the System.Windows.Forms.PaintEventArgs of the argument of the form's Paint event to the graphMotor:

private GraphMotor graph;
private void Data_Load(object sender, System.EventArgs e)
{
    //A new motor

    graph = new GraphMotor();      

    //I add two series of data

    graph.Graphs.Add(new ListData());
    graph.Graphs.Add(new ListData());

    //Set the color for each one

    graph.Graphs[0].DisplayColor = Color.DarkBlue;
    graph.Graphs[1].DisplayColor = Color.DarkGreen;

    PocketGraphBar.GraphPoint p;

    //Generate de dumy data

    for(int i = 1; i < 11; i++)
    {
       //A new point

       p = new PocketGraphBar.GraphPoint();
       p.X = Convert.ToDecimal(i);
       p.Y = Convert.ToDecimal(i * 100);
       graph.Graphs[0].Add(p);

       //Another new point

       p = new PocketGraphBar.GraphPoint();
       p.X = Convert.ToDecimal(i);
       p.Y = Convert.ToDecimal(i * 50);
       graph.Graphs[1].Add(p);
    }            
}
private void Data_Paint(object sender, 
       System.Windows.Forms.PaintEventArgs e)
{
 try
 {
     //In the load event the the object was filled

     //Here we only set its properties

    
     graph.LeftMargin = 20;
     graph.LegendFont = new System.Drawing.Font("Arial", 
                        8.25F, System.Drawing.FontStyle.Regular);
     graph.AxisColor = Color.Black;
     graph.MaxHeight = 200;
     //The width of each bar

     graph.Thick = 6;
     //The number of bars wa want to see 

     //for each series of data

     graph.DisplayTimes = 10;
     //Now solve this

     graph.DrawGraphs(e);               
 }
 catch(Exception ee)
 {
    MessageBox.Show(ee.ToString());
 }
}

Talking about the component, we have three classes:

  • GraphMotor: Is the controller class that resolves all the logic.
  • ListGraphs: Is a collection of a series of data we want to graph. It means we can have a composite bar chart.
  • ListData: Is a collection of the data we want to graph.
  • GraphPoint: A single key pair value, X and Y where Y depends on the value of X.

The namespace of these classes is PocketGraphBar.

Points of interest

  • I have used the decimal type in GraphPoint in order to put any kind of value using a simple cast or Convert.
  • The height of each bar is determined by value / maxValue * maxLength so don't worry if you need to graph values of N digits, scaling will be done.
  • It is possible to put any number of series of data with N key pair values since ListData and ListGraphs classes implement System.Collections.ICollection.
  • It should work fine for common Windows Forms applications.

Just remember the look and feel depends on the logic of the data you enter, this was designed for smart devices applications so don't expect too much. Bar charts consist of collections of X and Y values where X is continuous (1,2,3,4... or 2005, 2010, 2015...).

I think this would work as the basis to deliver more kinds of charts (pie, linear, area) but this work was done in just one afternoon.

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

pablojag


Member
Pablo studied Information System Engineering and graduated on may 2001 although he always had the idea of becoming a writer, idea that has not escaped from sight. At the present he works as a software developer leader in a Insurance Company in the team of Systems for Sale Force developing tools for policy selling. He has experience with Dot Net since May 2002 and has reached the third Start recognition from MSDN Latin America. He has knowledge in Compact Framework, Windows Forms and Asp Net. Pablo looks forward that his contributions in this forums help the comunity at the Code Project.
Occupation: Web Developer
Location: Mexico Mexico

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralI couldn't open the project properly. Pinmemberreinareina2:41 26 Mar '09  
GeneralMy vote of 1 Pinmembertecnic23:11 14 Jan '09  
Generalscaling problem PinmemberMember 259342114:25 27 Nov '08  
GeneralPie chart... PinmemberGeirFAndersen13:52 18 Jun '07  
GeneralMe parece muy interesante Pinmemberrhelena23:36 16 Nov '05  

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

PermaLink | Privacy | Terms of Use
Last Updated: 16 Nov 2005
Editor: Rinish Biju
Copyright 2005 by pablojag
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project