![]() |
Desktop Development »
Miscellaneous »
Miscellaneous Controls
Intermediate
License: The Code Project Open License (CPOL)
DataPlotter - linear or logarithmic display of 2D dataBy Hans-Jürgen SchmidtThe DataPlotter is a .NET control for graphical display of 2D data. For both the X and Y axis a linear or logarithmic (any base) scaling can be selected. |
C#.NET 1.0, Win2K, WinXP, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

The DataPlotter is a .NET control for graphical display of 2D data. For both the X and Y axis a linear or logarithmic (any base) scaling can be selected. Also for both axis the data range can be specified.
Maybe it is of interest to somebody else out there. At least it can be used as another sample on how to fiddle with GDI+ in .NET.
For charting in the .NET world there is still the good old MSChart ActiveX control or you have to buy one of the new .NET controls on the market.
Since neither the MSChart control made me happy for my purpose nor did I want to spend money, I decided to start something on my own. This project is nothing fancy or new -- it's just my first steps in .NET graphics.
The implementation of DataPlotter is quite simple: It's a .NET Windows control library with a bunch of properties. Everything else happens in the OnPaint function.
These are the properties:
Color ColorDraw |
The color of the data line |
Color ColorGrid |
The color of the gird lines |
Color ColorBg |
The background color |
Color ColorAxis |
The color of the axis and text |
Font FontAxis |
The font for the text |
long PenWidth |
The width of the data line |
DrawModeType drawMode |
Draw mode for the data points (Line, Dot, Bar) |
long BorderTop |
The internal border at the top |
long BorderLeft |
The internal border at the left |
long BorderBottom |
The internal border at the bottom |
long BorderRight |
The internal border at the right |
double XRangeStart |
The start of the data range on the x axis |
double XRangeEnd |
The end of the data range on the x axis |
double YRangeStart |
The start of the data range on the y axis |
double YRangeEnd |
The end of the data range on the y axis |
double XGrid |
The spacing for the linear grid in x direction. Ignored for log. views |
double YGrid |
The spacing for the linear grid in y direction. Ignored for log. views |
long XLogBase |
The base for log. views in x direction. If < 2 then a linear view is displayed |
long YLogBase |
The base for log. views in y direction. If < 2 then a linear view is displayed |
double[] XData |
The data to be displayed for x. |
double[] YData |
The data to be displayed for y. |
A few hints on some properties:
LogBase property is below 2 then a linear scaling is selected. Otherwise the number is the base for logarithmic scaling. Typically use 0 for linear and 10 for logarithmic scales.
RangeStart and RangeEnd properties, e.g. 0.01 to 1000 for a LogBase of 10.
A short walkthrough of the OnPaint function:
RangeStart to RangeEnd are mapped onto points of the axis grid considering the LogBase scales. Invalid points (detected by exception handler) are skipped by reusing the last valid point.
DrawMode. The DataPlotter is an assembly that can be used as shown in the DataPlotterTest application. This demo has four buttons with sample data for the possible linear/logarithmic scalings. There is also a property grid so see/change the DataPlotter's properties.
The current implementation of DataPlotter served my purpose quite well. But there are many useful extensions and enhancements I can think of:
Help yourself and let me know about your own enhancements.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 Oct 2003 Editor: Smitha Vijayan |
Copyright 2003 by Hans-Jürgen Schmidt Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |