|
by
George Martin
Start ý How
I Did It ý Background Painting ý Data
Plotting ý Sources and PDF
BACKGROUND PAINTING
I sized the picture box so that it fit
comfortably on my screen. Iýve got a 17ý
monitor and Iým using 1152 ý 864 (pixels) resolution. PictureBox is
12000 ý 7789 (twips). If youýve got a smaller screen, you could reduce
the size of the PictureBox or keep the size large and implement scroll
bars.
The pixel (short for picture element)
is the smallest graphical unit of measurement on the screen. Pixel
size and spacing is screen dependent (i.e., its dimensions vary with
the system display and resolution). A twip, on the other hand, is
a screen-independent unit of measure equal to one-twentieth of a printerýs
point. There are approximately 1440 twips to an inch.
Next, I created a box that outlined the
active area for the chart. The boxýs corner coordinates were:
TL_X 400 top left X
TL_Y 200 top left Y
BR_X 11200 bottom right X
BR_Y 7200 bottom right Y
And, I drew that box using the following
VB statement:
oPrinter.Line (TL_X, TL_Y)-(BR_X,
BR_Y), , B
Notice that I created the constants TL_X,
TL_Y, etc. to define the borderýs outline. That way I could
change the size by altering these constants and not rewriting the
code.
I next put grid marks in the active area.
I created STEP_Y and STEP_X constants for grid spacing
with STEP_X being just an arbitrary setting equal to 500 twips,
while STEP_Y was defined to represent 0 to 100% grid spacing
on the y axis.
STEP_Y = (SIZE_Y / 255) * 25.5
Remember that we have channels 1ý4 that
are 8-bit A/D inputs, and channels 5 and 6 that are 12-bit A/D inputs.
The 8-bit inputs range from 0 to 255 counts, while the 12-bit inputs
range from 0 to 4095 counts. So, a percentage seems like a good choice
for y-axis scaling. You could choose engineering units or a
nonlinear scaling that suits your specific application. Keep in mind
that the more math you perform, the slower the graphing becomes.
The actual grid marks are drawn with
this code:
Const GRID = 20
For x = TL_X To BR_X Step STEP_X
For y = BR_Y To TL_Y Step -STEP_Y
oPrinter.Line (x - GRID, y)-(x +
GRID, y)
oPrinter.Line (x, y - GRID)-(x, y
+ GRID)
Next y
Next x
Grid markers are made by drawing a horizontal
line then a vertical one. The width of the lines are defined by the
constant GRID. If you change the value of GRID, the
size of the hash marks change.
The y-axis scaling is printed
using this routine:
px = TL_X ý 350 ' Start the
text to the left of the box
x = 0 ' Value
For y = BR_Y To TL_Y Step -STEP_Y
oPrinter.CurrentX = px
oPrinter.CurrentY = y - 100
oPrinter.Print x
x = x + 10
Next y
The variable px is the x-coordinate
for the label and it remains constant. The variable x is the
numeric value for the grid marker. The variable y represents
the y coordinate for the label, and it changes for each grid
mark. As you can see, this code fragment steps through the grid axis,
labeling each point.
x-axis labeling is similar, except
that no scaling is implied. Larger numbers positioned on the right
work best. The data is plotted from left to right until the end is
reached. At that point, the process starts over again without erasing
any of the previously plotted data. This plotting style is only useful
for some monitoring situations, but you may wish to modify this charting
technique to find one more useful for your application. Hopefully,
Iýve given you enough of the basics to accomplish that.
py = BR_Y + 100 ' Start the text to
the bottom of the box
y = 0 ' Value
For x = TL_X To BR_X Step STEP_X
oPrinter.CurrentX = x - 100
oPrinter.CurrentY = py
oPrinter.Print y
y = y + 10
Next x
I started to tune this loop to represent
readings. If you change the size of any of the constants being plotted,
how fast the readings come in, or the step size of the x direction,
then all the scaling needs to be changed. I could do this with formulas,
but that slows down the code. So, in keeping with the lean, mean design
approach, this is it.
My last task is to print a list of the
channels and the colors used for each channel. I filled in the boxes
with the color just for clarity, using simple colors (the first six
I came across) for the channels.
PREVIOUS NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ýCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |