Click here to Skip to main content
Licence 
First Posted 24 Sep 2006
Views 74,414
Downloads 3,605
Bookmarked 82 times

Realtime Chart and Graph in One

By | 16 May 2007 | Article
A basic Chart and Graph control.

Sample Image - ChartGraph.png

Introduction

I worked on a project in which I needed a graph control. Later on, I was also required to use a chart control. So I thought, hey, let's just combine them both into one nice and simple control.

Using the code

This control is very simple to use. First, we must create the control and initialize it.

//Creating the control
private ChartControl.ChartControlForm chartControlForm1;
chartControlForm1 = new ChartControl.ChartControlForm();
//Initializing the Control
chartControlForm1.InitChart();

Now we can start adding values.

//Adding Values to the control
float ValueAdd;
ValueAdd = 5.3;
chartControlForm1.AddValue(ValueAdd);

As we add the values, the control automatically redraws itself, so there is no need to call any function.

The variable in charge of the Graph/Chart mode is OpenType. Please note that its default value is ChartControlOpenType.Bar.

Change to Graph mode:

chartControlForm1.OpenType = ChartControl.ChartControlOpenType.Graph;

Change to Chart mode:

chartControlForm1.OpenType = ChartControl.ChartControlOpenType.Bar;

Additional Features

Loading from an array/list can easily be done by using the overloaded function LoadFromValues (may receive a float Array or an ArrayList).

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

Roy Reznik



Israel Israel

Member

I've been into programming for the last 5 years, doing all sort of stuff, from the old dos borland c++ to C#.NET.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionReset chart data PinmemberMember 87076244:28 4 Apr '12  
QuestionRealTime graph Pinmembercicekbilal200222:51 3 Feb '12  
AnswerRe: RealTime graph PinmemberMazen el Senih7:46 6 Feb '12  
Generalreply! Pinmemberluongvn2:35 26 Feb '11  
GeneralRe: reply! PinmemberRoy Reznik7:54 14 May '11  
GeneralWeb Version Pinmembergirishmeena0:12 21 Sep '10  
QuestionHow could i adjust with all values when array exceed range of values? Pinmemberhuynhdangthai23:52 27 Jul '10  
QuestionI got some problem with it, help please.. Pinmemberrpurnama18:41 15 Feb '10  
Generalcannot run... Pinmemberyanadi6:02 30 May '09  
AnswerRe: cannot run... PinmemberRoy Reznik3:04 26 Jun '09  
GeneralMy Solution for the exception Pinmemberrcn2116:10 18 May '09  
GeneralRe: My Solution for the exception PinmemberRoy Reznik3:10 26 Jun '09  
GeneralRe: My Solution for the exception PinmemberNeoDimension2:15 5 Aug '09  
GeneralChange bar width Pinmemberelcharro5:59 10 Aug '07  
GeneralImplementing realtime graph [modified] Pinmemberjamezun21:30 18 Jun '07  
GeneralThanks for the update! PinmemberMarc Leger8:51 19 May '07  
QuestionLoad Array PinmemberGwannoes23:04 10 May '07  
AnswerRe: Load Array PinmemberRoy Rez10:10 16 May '07  
Generaltest application issues and chart control issues PinmemberToothRobber10:09 10 Nov '06  

Hello Roy
 
I had problems with you test applicaiton and its solution and had to build my own. To test your application I created an applicaiton that would generated random data and pass it to you control using a background thread.
 
If you would like my test application please drop me a message.
 
I found that your control generates an exception after a minute or two of running on the random number generator.
 

----
if (Values[i] < 0) // Less than 0, UnderColor is used
{
if (IntCmp(Values[i], Values[i - 1]) < 0) //if it goes above 0
 
----
The Error
 
{"Index was outside the bounds of the array."}
" at ChartControl.ChartControlForm.DrawChart() in C:\\code\\NET\\Controls\\ChartControl\\ChartControlForm.cs:line 283\r\n at ChartControl.ChartControlForm.AddValue(Single val) in C:\\code\\NET\\Controls\\ChartControl\\ChartControlForm.cs:line 147\r\n at ChartTrialProgram.frmMain.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in C:\\code\\NET\\Controls\\ChartControl\\ChartTrialProgram\\frmMain.cs:line 66\r\n at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)\r\n at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)"
 
To fix this I would use a circular buffer for you data values this would keep the data list to a prodictable size.
 
Also the background (green and black grid) moves and I think your control work look better if you could stop this.
 
Robert
 


GeneralRe: test application issues and chart control issues PinmemberRoy Rez10:19 10 Nov '06  
QuestionReal Time? PinmemberMBirchmeier10:19 6 Nov '06  
AnswerRe: Real Time? PinmemberRoy Rez10:17 10 Nov '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 16 May 2007
Article Copyright 2006 by Roy Reznik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid