Macro: CHART
#IFSAME !1 BAR
indicate bar$chart true
#ENDIF
#IFSAME !1 LINE
indicate line$chart true
#ENDIF
#IFSAME !1 PIE
indicate pie$chart true
#ENDIF
#IF (!0>1)
trim !2 to graph$title
#ELSE
move '' to graph$title
#ENDIF
#IFSAME !1 PIE
#ELSE
#IF (!0>2)
trim !3 to graph$ytitle
#ELSE
move '' to graph$ytitle
#ENDIF
#ENDIF
#IFSAME !1 PIE
#ELSE
#IF (!0>3)
trim !4 to graph$xtitle
#ELSE
move '' to graph$xtitle
#ENDIF
#ENDIF
move |VI34 to |VI35
gosub do$chart
screenmode |VI35
#IFSAME !1 BAR
indicate bar$chart false
#ENDIF
#IFSAME !1 LINE
indicate line$chart false
#ENDIF
#IFSAME !1 PIE
indicate pie$chart false
#ENDIF
#IFDEF DO$CHART
#ELSE
goto do$chart$end
do$chart:
graph_sum total$value num$values
graph_stat min$value max$value
gosub sc$init
gosub calc$value
gosub draw$axis
indicate first$value true
for graph$num from 1 to num$values
[first$value] graph_getfirst graph$label value$
[~first$value] graph_getnext graph$label value$
trim graph$label to graph$label
[bar$chart] gosub graph$bar
[line$chart] gosub graph$line
[pie$chart] gosub graph$pie
indicate first$value false
loop
gosub_return
graph$bar:
move (axis$base+((value$/(max$value-min$value))*800)) to upper$right$y
move (lower$left$x+bar$width) to upper$right$x
bar lower$left$x lower$left$y upper$right$x upper$right$y chart$color
[~bottom$label] grxy lower$left$x (upper$right$y-50)
[ bottom$label] grxy lower$left$x 50
screenmode label$color
grshow graph$label
move (lower$left$x+bar$width+bar$space) to lower$left$x
return
graph$line:
move (axis$base+((value$/(max$value-min$value))*800)) to lower$left$y
grxy lower$left$x lower$left$y
[~first$value] line last$x last$y chart$color
circle lower$left$x lower$left$y 5 axis$color
move lower$left$x to last$x
move lower$left$y to last$y
[~bottom$label] grxy lower$left$x (lower$left$y-50)
[ bottom$label] grxy lower$left$x 50
screenmode label$color
grshow graph$label
move (lower$left$x+bar$width+bar$space) to lower$left$x
return
graph$pie:
move ((6.28318 * (value$/total$value)) + last$radian) to radian
move ((radian+last$radian)/2) to mid$radian
move (cos(mid$radian)*30+500) to last$x
move (sin(mid$radian)*30) to last$y
move (last$y + (last$y*dev$y/dev$x) + 500) to last$y
grxy last$x last$y
pie radius last$radian radian chart$color axis$color
move radian to last$radian
move (cos(mid$radian)*(radius+50)+500) to last$x
move (sin(mid$radian)*(radius+50)) to last$y
move (last$y + (last$y*dev$y/dev$x) + 500) to last$y
if last$x lt 500 ;
move (0 max (last$x - (length(graph$label)*8000/dev$x))) to last$x
grxy last$x last$y
screenmode label$color
grshow graph$label
return
sc$init:
setworld 0 0 1000 1000
clearscreen
return
calc$value:
move (max$value*1.05) to max$value
move (min$value*1.05) to min$value
if min$value gt 0 move 0 to min$value // zero base pos ranges
if max$value lt 0 move 0 to max$value
real scaler$
integer increments$
move (10^(integer(log(max$value max -min$value)/log(10)))) to scaler$
move (max$value/scaler$+1) to increments$
move (scaler$*increments$) to max$value
if min$value lt 0 begin
move (scaler$*integer(min$value/scaler$-1)) to min$value
move (increments$-integer(min$value/scaler$)) to increments$
end
if increments$ le 6 move (increments$*2) to increments$
move ((((-min$value max min$value)/(max$value-min$value)) ;
* 800)+100) to axis$base
move axis$base to lower$left$y
return
center$title:
move 3 to text$size
center$title2:
repeat
move (text$size-1) to text$size
move (((gr$tmp-((length(graph$label)+1)* ;
(text$size*8)))/2)*1000/gr$tmp) to text$center
until text$center ge 0
return
draw$axis:
getdrange dev$x dev$y
screenmode label$color
if (length(graph$title)) gt 0 begin
move dev$x to gr$tmp
move graph$title to graph$label
gosub center$title
if (text$size*8000/dev$y) gt 50 gosub center$title2
set_text text$size 0
grxy text$center 950
grshow graph$title
end
[pie$chart] begin
indicate first$value true
move 0 to gr$tmp
for graph$num from 1 to num$values
[first$value] graph_getfirst graph$label value$
[~first$value] graph_getnext graph$label value$
trim graph$label to graph$label
move (gr$tmp max length(graph$label)) to gr$tmp
indicate first$value false
loop
set_text 1 0
move 0 to last$radian
move ((50 max ((dev$x*0.4)-(gr$tmp*8)*1000/dev$x)) min 190) to radius
return
end
if (length(graph$xtitle)) gt 0 begin
move graph$xtitle to graph$label
gosub center$title
set_text text$size 0
move (text$size*8000.0/dev$y) to gr$tmp
// move ((text$size+1)*8000.0/dev$y) to gr$tmp
grxy text$center gr$tmp
grshow graph$xtitle
setworld 0 (-gr$tmp) 1000 1000
end
if (length(graph$ytitle)) gt 0 begin
move dev$y to gr$tmp
move graph$ytitle to graph$label
gosub center$title
set_text text$size 1
grxy 0 text$center
grshow graph$ytitle
end
else move 0 to text$size
set_text 1 0
screenmode label$color
move min$value to value$
integer indent$
move 0 to indent$
move ((max$value-min$value)/increments$) to value$step
while value$ le max$value
move (axis$base+((value$/(max$value-min$value))*800)) ;
to upper$right$y
grxy (((text$size*8)+2)*1000/dev$x) upper$right$y
grshow value$
move (indent$ max length(value$)) to indent$
move (value$+value$step) to value$
end
move ((((indent$+text$size)*8)+12)*1000/dev$x) to indent$
move (real(900-indent$)/num$values * 0.8) to bar$width
move (real(900-indent$)/num$values * 0.2) to bar$space
move (indent$+bar$space) to lower$left$x
bar (indent$-10) 90 indent$ 900 axis$color
bar indent$ 90 900 100 axis$color
grxy indent$ axis$base
line 900 axis$base
return
do$chart$end:
#ENDIF