[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Description: Draw a pie chart
Mapped Command: DRAW PIE CHART AT
FUNCTION __DrawPieChart(Pos1,Pos2,dbf,field,filter,pat,col,label,offset,slice,radius,percent,noconnect)
local n, maxvalue, divisions, scalefact, increment
local pattern := 1 // establish the beginning pattern
local color := 2 // establish the beginning color
local select_ := select() // save the current area
local labeltxt:= "" // establish a blank label accumulator
label := if(label == NIL,"",label) // get the specified label (not sure if this has to be a field)
offset := if(offset == NIL,PieLabelOffSet,offset) // set the offset if not specified
slice := if(slice == NIL,0,slice) // pie slice to explode
radius := if(radius == NIL,PieChartRadius,radius) // determine the radius, default to 20
use &dbf new // open the plot database
datareset() // clear the dGE daya array
if filter != NIL // is there a filter statement?
set filter to &filter // set the requested filter
go top // reset the database pointer
endif // if filter != nil
maxvalue := &field // start with the first value in the plot field
n := 1 // establish a bar counter
do while .not. eof() // loop through all the valid records
maxvalue := if(&field > maxvalue,&field,maxvalue) // get the max value of each slice
skip // next valid record
n ++ // increment the slice counter
enddo // keep doing it 'till the eof()
go top // back to the first record
n := 1 // establish a slice counter
do while .not. eof() // loop through the valid records
datastore(if(&field<0,0,&field*(1000/maxvalue)),if(pat,pattern,20),if(n == slice,1,0),if(col,color,__DgeColor(setcolor())))
color := if(color == 20,1,if(color == 7,color+2,color+1))
pattern := if(pattern == 20,1,pattern+1) // increment the pattern
if percent == 0 // if percentages are not being used for labels
labeltxt := labeltxt + &label // accumulate the label string
endif // if percent == 0
n ++ // increment the pie slice counter (always = n-1)
skip // next valid record
enddo // do while .not. eof() // loop through the valid records
piechart(__XdGE(Pos2),__YdGE(Pos1),__XdGE_(radius)) // draw the pie chart
do case // evaluate label style
case percent > 0 // percentage labels
labelpie(__XdGE_(offset),__XdGE_(radius*if(slice > 0,1.35,1)),0,0,percent+noconnect,__dGEColor(setcolor()),"")
case .not. empty(label) // text labels
labelpie(__XdGE_(offset),__XdGE_(radius*if(slice > 0,1.35,1)),len(&label),0,noconnect,__dGEColor(setcolor()),labeltxt)
endcase
use // close plot database
select(select_) // restore area
RETURN(Void)
See Also:
DRAW PIE CHART AT
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson