Graphics and Visual Basic...

AtlantaBob

Golden Member
Jun 16, 2004
1,034
0
0
I'm continuing to write a proof-of-concept program for grad school. This program needs to be able to graphically display data that comes from an array of data (the data will be color coded, so the smallest decile will be colored blue, the highest red and the rest in-between).

In Visual Basic (express edition), I've been able to write the following general code (assuming that the shape is a square). Granted the variables used in defining the rectangles could use some work; however, is the general approach right? Or is there a nicer (and faster) way to draw squares in visual basic?

Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics

For x = 0 To intNumberOfTiles
For y = 0 To intNumberOfTiles
formGraphics.FillRectangle(myBrush, New Rectangle(x * intMultiplier, y * intMultiplier, intWidth, intWidth))
Next
Next

THANKS!
 

cker

Member
Dec 19, 2005
175
0
0
Are you tiling for any particular reason? For the case of squares, could you just draw it in one command? Would this work for your square:

intSideLength = intNumberOfTiles * intMultiplier
formGraphics.FillRectangle(myBrush, New Rectangle(0, 0, intSideLength, intSideLength))

It's almost certainly not good code, since it's been a few years since I touched VB (and that was mainly VB6 and 97). The idea is to do it in one op rather than many - your algorithm there will require (intNumberOfTiles^2) operations. I did a _little_ graphical stuff in C and Perl, and generally my approach was to get in my data set first, then apply some series of transforms to get my graphics data as coordinates suitable for the draw-a-filled-rectangle function of choice, then draw the bars.
 

AtlantaBob

Golden Member
Jun 16, 2004
1,034
0
0
cker,

Thanks for the input. I realize from a algorithm analysis perspective that it's going to take a heck of a lot longer to draw, but I'm not sure of how I'd write the code to do it more efficiently. (then again, I know nothing about programming, so perhaps someone can help out on this). The data's tiled because the underlying data represents information about a particular region of space (say a sqauare foot).

(Last minute edit, the spaces between the tiles are there just to make them more visible; don't need to have the spaces, although, since I was drawing each square individually, I figured I might as well put them in. But thanks for the reminder that I can draw the lines afterward.

Anyway, my data might look something like this, where the x's and o's will represent different values. (the underlying values will actually be floating point, but they'll be classed into groups -- the highest 10%, next highest 10%, etc.)

xoxoxxxooxxooxxoox
xxoxoxxxoxoxoxxxxo
xxoxoxooxoxoxoxoxo
oooooooxxxxoooooox
xoxxxoxoxoxoxoxxox

Edit, haven't had my coffee yet, in short, similar data values are non-contiguous

Would I want to try something like drawing a single non-convex polygon for each group?

Thanks again for your thoughts!
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
If you have money to spend, there are commercial charting and graphing / plotting packages. Try pparadise.com
 

AtlantaBob

Golden Member
Jun 16, 2004
1,034
0
0
Dave,

I suppose I could, but the buget is tight, and, sadly, it's fun to learn this stuff. Any books that you might suggest, or other methods of going about this?

Thanks!