High Speed, Feature Rich, and Easy-To-Use Graphs and Charts






4.92/5 (70 votes)
Nov 12, 2006
6 min read

230914

17075
High speed graphs and charts that are also very easy to configure and use. As easy as inserting a simple chart in MS Excel!
Introduction
This project was developed for the impatient developer (that's me sometimes, and probably you!) who's sitting late at night downloading charting libraries only to figure out that it's too complex to set up, isn't dynamic, and doesn't provide the necessary customizations.
Well, GraphComponents
hopes to provide an answer to these common problems. In short, GraphComponents
is a .NET user control that provides you the following features:
- Easy to use in the Visual Studio designer IDE
- Easy to configure during runtime
- High speed updating
- Rich features like custom color settings, custom background settings, smart numbering, reference values and lines, grids, transparent bars, etc.
GraphComponents
currently supports Bar Graphs, Stacked Bar Graphs (Multi-bar Graphs), and a N-Channel Plotter Oscilloscope (Plotter CRO). Future versions should see other kinds of graphs too.
Usage
GraphComponents
is accessible as a control from the control toolbox in Visual Studio .NET. To access GraphComponents
, first launch Visual Studio .NET, and create a new Windows Application project. Open the Form Design so that it appears in the current window. View the toolbox using the View/Toolbox menu command. Right-click inside the "General" or "Components" sub-pane of the tool box, and select the "Add/Remove Items..." option. In the "Customize Toolbox" dialog that appears, select ".NET Framework Components". Click "Browse...", and navigate to the GraphComponents.dll file. Once this file is added, you should see a BarGraph
, StackedBarGraph
, and a Plotter
option in the toolbox.
Using the Stacked Bar Graph
- Create a new Windows Application project as described above.
- Drag and drop the
StackedBarGraph
onto the form. - Drag and drop two
Button
s (Button1
andButton2
) onto the form. - Double click
Button1
. This will place aButton1_Click()
function in your C# file. - Double click
Button2
. This will place aButton2_Click()
function in your C# file. - Add the following code in the
Button1_Click()
function:// Increment the bar value by 10 stackedBarGraph1.Bars[1].BarValue += 10; stackedBarGraph1.UpdateDisplay ();
- Add the following code in the
Button2_Click()
function:// Decrement the bar value by 10 stackedBarGraph1.Bars[1].BarValue -= 10; stackedBarGraph1.UpdateDisplay ();
- Build and run the application. You have a very basic framework ready for using the
StackedBarGraph
. Examine the sources of the walkthrough projects for both theBarGraph
and theStackedBarGraph
. - Now, getting back to the Form Design view, adjust some of the properties of the graph in the Properties pane.
- Set the
BarOrientation
property toHorizontal
to get a horizontal bar graph. Notice that any change you make is instantly updated in the form's design view itself. - To perform high speed updating for measuring various things like pulse count, cylinder pressure of a 6 cylinder engine, music tones etc., you just have to set up a timer and update the bars accordingly. Examine the source of the GraphUsageDemo application for configuring high speed displays.
Using the Plotter Oscilloscope
The plotter oscilloscope is useful when you want to capture various input signals and observe them. The Performance tab of the Windows Task Manager has two simple plotters for monitoring CPU usage history and page file usage history. On Windows 2000 or XP, you can view the Windows Task Manager by pressing Ctrl + Shift and then pressing Esc.
Another thing about plotters and CROs in general is that they receive inputs through their 'channels'. If you observe the Plotter in the GraphUsageDemo application, you can see that the Advanced Body Measurement System measures four parameters (voltage, current, body pulses, and metabolism) through its four channels. While a simple low-end CRO has two channels, a hi-fi CRO (called as a spectrum analyser) can have many input channels. OK, enough with electronics theory! Let's get back to .NET.
- To use a plotter, create a new Windows Application project as described above.
- Drag and drop the
Plotter
onto the form. - In the form's constructor, add the following line after the
InitializeComponent();
line:// Start the plotter plotter1.Start (); // Set the plot rate to 200 ms - which means that // the plotter's samples are spaced 200 milisecond apart plotter1.PlotRate = 200;
- Go back to the Form Design view and drag and drop a
Button
(Button1
) onto the form. - Double click
Button1
. This will place aButton1_Click()
function in your C# file. - Add the following code in the
Button1_Click()
function:// Generate random values for plotting on the 1st and 2nd channel Random r = new Random ( (int) DateTime.Now.Ticks); plotter1.Channels[0].CurrentValue = r.Next (0, 100); plotter1.Channels[1].CurrentValue = r.Next (0, 5); plotter1.UpdateDisplay ();
- Build and run the application. Keep clicking
Button1
, and the plotter starts plotting two separate lines for its two channels. You now have a very basic framework ready for using thePlotter
. On the top left hand corner of the plotter, you can see the < and > icons. These are used for navigating to the next and previous channels. On surfing channels, the currently active channel appears brighter. The + and - icons below are used for offset adjustment. You can experiment by clicking these buttons and repeatedly clickingButton1
. - By default, channels 1 and 2 are enabled, while channels 3 and 4 are disabled. The X axis time range is set to 9 seconds. Once the plotter has reached the right side, it automatically scrolls to the left. Also, by default, the upper and lower limits for channel 1 are set to 100 and 0. The upper and lower limits for channel 2 are set to 5 and 0.
- Examine the sources of the PlotterWalkThrough project and the
Plotter
part of GraphUsageDemo. - Now, getting back to the Form Design view, adjust some of the properties of the plotter in the Properties pane. For example, adjust the
PlotRate
,GraphMarginLeft
, andGraphMarginTop
. - To perform high speed updating for measuring various things like voltages, currents, etc., you just have to set up a timer. Also note that the
PlotRate
must tally with the timer'sInterval
to get an accurate measurement. Examine the source of the GraphUsageDemo application for configuring high speed displays.
While using this in your code, it is useful to know the following things:
Start()
starts the plotter.Stop()
stops the plotter. If the plotter has scrolled, then a scroll bar appears allowing you to see the earlier plots.Start()
andStop()
also act like Resume and Pause. So you can pause, examine the graphs, and resume by using the same two functions.Reset()
erases the plotter and makes it fresh for using again.- The
CompressedMode
property allows you to view the entire plot in the graph area without any scrolling. NextChannel()
andPreviousChannel()
allow you to surf channels.- A channel can be enabled or disabled. You cannot see the output of a disabled channel.
- If you are not satisfied with four channels, you can add more channels by easily changing the source code. The upper limit is based on how satisfied you are with the performance. So, you could possibly set up 8 channels and observe the data bus of an 8-bit microprocessor.
Acknowledgements
I would like to thank my wife Shubha, for providing me with some cool ideas with respect to usability, and for lots of other small things. Also, thanks to some of my friends in my current and previous companies, with whom I discuss a lot about software.
Conclusion
Hope you find this library useful and that you enjoy using it. Please send your criticisms, bugs, ideas for new features, and suggestions to anupshubha@yahoo.com. I would be especially happy with any ideas adhering to the "Keep It Simple" principle.