|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionI 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 codeThe 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 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:
The namespace of these classes is Points of interest
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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||