Drawing a graph by script
Mark Swindell
mdswindell at cruzio.com
Sun Mar 1 15:53:04 EST 2009
Thanks Bjornke, Victoras, and Craig. I've got something that works
now. This is the method I used. There is a preexisting rectangle
called "backRect" and a user field called "numUnits". This seems to
work pretty well so far.
Mark
ON makeLines
put field "numUnits" into vNumUnits -- how many lines (units)
high derived from user input field
lock screen
put round((the height of grc "backRect")/(vNumUnits)) into
vBackIncrement -- how much space between lines, must be rounded
because pixels are whole numbers
put "x,x,x,x" into vThePoints -- starting point for first line
put item 4 of the rect of graphic "backRect" into item 2 of
vThePoints -- bottom of rectangle = (top of first line)
put item 4 of the rect of graphic "backRect" into item 4 of
vThePoints -- bottom of rectangle = (bottom of first line)
put item 1 of the rect of graphic "backRect" into item 1 of
vThePoints -- left side of line matches left side of rect
put item 3 of the rect of graphic "backRect" into item 3 of
vThePoints -- right side of line matches right side of rect
REPEAT (vNumUnits-1) times -- so top of rectangle will represent
last line
subtract vBackIncrement from item 2 of vThePoints -- each
line draws itself higher, from bottom up
subtract vBackIncrement from item 4 of vThePoints -- " " "
set the style of the templategraphic to "line" -- defines
graphic type
set the points of the templategraphic to vThePoints --
defines graphic location
create graphic "myLine" -- creates line and places at correct
location
END repeat
set the height of grc "backRect" to (the bottom of grc
"backRect") - (item 4 of vThePoints)+vBackIncrement -- because spaces
between lines may need to be rounded, rectangle itself needs to be
tweaked
set the top of grc "backRect" to (item 4 of vThePoints) -
vBackIncrement -- adjusts the rectangle up so all increments are even
unlock screen
reset the templateGraphic
END makeLines
On Mar 1, 2009, at 3:44 AM, Björnke von Gierke wrote:
> The easiest way would be to buy malte's new chart engine (available
> on the rev site).
>
> If you're more interested in the learning experience, i suggest
> setting the points of a graphic. if you have an empty line in the
> points of a graphic, the two points above and below it won't be
> connected, so you can even make the grid and the actual graph from
> the same graphic. It's very easy to scale this to several heights:
> Just use a very large rect as orignal, then shrink to your desired
> size.
>
> On the other hand, if you set the markers, you'll get graph markers
> for free, so to say. But then you can't use the same graphic for
> everything at once.
>
> On 28 Feb 2009, at 21:13, Mark Swindell wrote:
>
>> What would be the best way to draw a simple graph by script?
>>
>> All I need is a rectangle with horizontal lines drawn across it at
>> the correct intervals (height/100) or whatever the number of lines
>> is to be. I've been looking in the docs but still not sure how to
>> implement this. I also played around with using a list field and
>> setting the line height, but this isn't as accurate as I'd like.
>
> --
>
> official ChatRev page:
> http://bjoernke.com/runrev/chatrev.php
>
> Chat with other RunRev developers:
> go stack URL "http://bjoernke.com/stacks/chatrev/chatrev1.3b3.rev"
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list