[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Description: Draw a bar chart
Mapped Command: DRAW BAR CHART AT
FUNCTION __DrawBarChart(Pos1,Pos2,dbf,field,label,width,height,division,filter,solid,dotted,dashed,box,pat,color,three_d,horiz)
   local n, select_, xlabeltxt, ylabeltxt, maxvalue, divisions, scalefact, increment
   local gmode := three_d + horiz                // calculate the chart mode
   local amode := solid + dotted + dashed + box  // calculate the axis mode
   local pattern := 1                            // establish a pattern increment
   label     := if(label == NIL,"",label)        // establish X axes label default
   width     := if(width == NIL,BarChartWidth,width)  // establish chart width
   height    := if(height == NIL,BarChartHeight,height)  // establish chart height
   color     := if(color == NIL,"",color)
   if " " $ color .and. "BRIG" $ upper(color)
      color := substr(color,at("BRIG",upper(color)))
      color := ltrim(substr(color,at(" ",color)))
      color := "bright " + trim(substr(color,1,at(" ",color)))
   else
      if " " $ color
         color := trim(substr(color,1,at(" ",color)))
      endif                                      // if " " $ color
   endif                                         // if " " $ color .and. "brig" $ upper(color)
   select_   := select()                         // save the current area
   xlabeltxt := ylabeltxt := ""                  // establish the label text memvar
   use &dbf new                                  // open the plot database
   datareset()                                   // clear the dGE data array
   if filter != NIL                              // are we filtering the dbf?
      set filter to &filter                      // establish a filter
      go top                                     // reset the database pointer
   endif                                         // if filter != nil
   maxvalue := &field                            // start with the first value
   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
      skip                                       // next valid record
      n ++                                       // increment the bar counter
   enddo
   maxvalue  := 1.10 * maxvalue                  // increase the max by 10%
   division  := if(division == NIL,maxvalue/4,division)
   divisions := int(maxvalue/division)           // establish default dependent value
   scalefact := __YdGE_(height+2)/maxvalue
   for n := 1 to divisions - 1                   // create the y label text
      ylabeltxt := ylabeltxt + str(division * n,5)
   next
   n := 1                                        // establish a bar counter
   go top
   do while .not. eof()                          // loop through all the valid records
      datastore(scalefact * &field,if(pat,pattern,0),0,if(empty(color),__DgeColor(setcolor()),__WordToColor(color)))
      pattern := if(pattern == 20,1,pattern+1)   // increment the pattern
      if len(label) > 0
         xlabeltxt := xlabeltxt + &label         // accumulate the label string
      endif
      n ++                                       // increment the bar counter
      skip                                       // next valid record
   enddo
   increment := __XdGE(width)/n                  // calculate the increment
   xyaxes(__XdGE(Pos2-2),__YdGE(Pos1+.5),__XdGE_(width),__YdGE_(height+2),n,divisions,amode,__DgeColor(setcolor()))
   labelx(__XdGE(Pos2+.75),__YdGE(Pos1+2),increment,if(len(label)>0,len(&label),0),0,BarXLabels,__DgeColor(setcolor()),xlabeltxt)
   labely(__XdGE(Pos2-(5 + 2.5)),__YdGE(Pos1-1),__YdGE_(height+2)/divisions,5,0,0,__DgeColor(setcolor()),ylabeltxt)
   bargraph(__XdGE(Pos2),__YdGE(Pos1),increment,gmode,1)  // display the bar chart
   use                                           // close plot database
   select(select_)                               // restore area
RETURN(Void)

See Also: DRAW BAR CHART AT
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson