This is the code for creating a graph.
- Code: Select all Expand view
FUNCTION Chart1( )
LOCAL byear, eyear
Local aValues, aTitCol
Local oGWnd, oGraph, oColumn, ii
LOCAL oFontT
LOCAL nMo
LOCAL oWorkorders
// Lets initialize the variables first
LOCAL aInc[ 12 ]
LOCAL aCst[ 12 ]
LOCAL nCurYear := YEAR( DATE( ) )
MEMVAR oWnd
ASIZE( aCst, 12 )
AFILL( aInc, 0 )
AFILL( aCst, 0 )
// Now get the first day of the year
bYear := CTOD( '01/01/' + SUBSTR( STR( nCurYear, 4 ), 3, 2 ) )
eYear := CTOD( '12/31/' + SUBSTR( STR( nCurYear, 4 ), 3, 2 ) )
// Open the workorder database and go to the first date of the year
oWorkorders := TWorkorders():New( 4 )
oWorkorders:seek( bYear, .T. )
// Place the cursor in wait mode while processing
MsgWait( "Please wait while processing records ...", "Workorder Totals", 4 )
CursorWait()
// Browse the data and assemble the data: income and cost ( parts, labor, sublet )
DO WHILE oWorkorders:paydat >= bYear .AND. oWorkorders:paydat <= eYear .AND. !oWorkorders:eof()
// Check for the month
nMo := MONTH( oWorkorders:paydat )
// Apply the data to the proper month
aCst[ nMo ] += oWorkorders:cstpar + oWorkorders:cstlab + oWorkorders:cstsub
aInc[ nMo ] += oWorkorders:srvtpa + oWorkorders:srvnpa + oWorkorders:srvtgo + oWorkorders:srvngo + ;
oWorkorders:srvtla + oWorkorders:srvnla + oWorkorders:srvtsu + oWorkorders:srvnsu
// Skip to the next record
oWorkorders:skip()
ENDDO
oWorkorders:close( )
CursorArrow( )
aValues := { { "Jan", aInc[1],aCst[1] }, ;
{ "Feb", aInc[2],aCst[2] }, ;
{ "Mar", aInc[3],aCst[3] }, ;
{ "Apr", aInc[4],aCst[4] }, ;
{ "May", aInc[5],aCst[5] }, ;
{ "Jun", aInc[6],aCst[6] }, ;
{ "Jul", aInc[7],aCst[7] }, ;
{ "Aug", aInc[8],aCst[8] }, ;
{ "Sep", aInc[9],aCst[9] }, ;
{ "Oct", aInc[10],aCst[10] }, ;
{ "Nov", aInc[11],aCst[11] }, ;
{ "Dec", aInc[12],aCst[12] } ;
}
aTitCol := { { "Income", CLR_GREEN }, ;
{ "Expense", CLR_YELLOW } }
//WINDOW para grafica
oGWnd := GraWnd():New( 12,22 ,45 ,130 , "Annual Income & Expense Summary", GraServer():New(aValues) )
//Sin ToolBar
oGWnd:bToolBar := { || nil }
//Tomar grafica
oGraph := oGWnd:oGraph
oGraph:nRowView := 12
oGraph:oTitle:cText := DTOC( DATE ( ) )
//Fuente para Titulo
DEFINE FONT oFontT NAME "Arial" SIZE 0,-15 BOLD
oGraph:oTitle:oFontT := oFontT
oGraph:oSubTitle:cText:= "For the year " + DTOC( byear ) + " to " + DTOC( eyear )
//Subtitulo a la izquierda
oGraph:oSubTitle:AliLeft()
oGraph:oAxisX:cText := "Month"
oGraph:oAxisYL:cText := "Amount"
oGraph:lPopUp := .T.
//Sin linea punteada en Grid
oGraph:oAxisX:lDottedGrid := .F.
oGraph:oAxisYL:lDottedGrid := .F.
//Intervalo de AxisYL
oGraph:oAxisYL:nStepOne := 5000
//Color gris en oAxisYL:nAxisBase
oGraph:oAxisYL:nClrZ := CLR_GRAY
//Asignar automaticamente las Columnas del servidor de datos
oGraph:AutoData()
//Assign titles & colors to the columns
FOR ii = 1 TO oGraph:nColGraph()
oColumn := oGraph:GetColGraph(ii)
oColumn:cTitle := aTitCol[ii,1]
oColumn:nClrFill := aTitCol[ii,2]
NEXT ii
oGWnd:Activate()
oFontT:End()
RETURN (NIL)
I'm thinking that others may have used this also, and that it was either incorporated into FWH, or another class may be in use. So, before I write all new code for all my graphs, is it possible someone has already converted to code included with FWH, and could suggest the changes I would make to use the classes already in our library.
If not, I will rewrite the code ... because I would like to stop linking in 15 year old code. I'm sure there is a better way.
Thanks for your input.