Page 1 of 1

FWH Graphs

Posted: Tue Oct 22, 2019 7:45 pm
by TimStone
I have been using a very old graphics class made for FWH in about 2004. Because it was commonly distributed as G_SERVER and G_GRAPH, others may have used it also.

This is the code for creating a graph.

Code: Select all

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.

Re: FWH Graphs

Posted: Tue Oct 22, 2019 7:52 pm
by karinha

Re: FWH Graphs

Posted: Wed Oct 23, 2019 3:39 am
by nageswaragunupudi
Please use TGraph.

We are giving a very simple example to start with. Once you start using, you will find many options for different types of graphs and customize to your taste.

Code: Select all

#include "fivewin.ch"
#include "tgraph.ch"

function Main()

   local oDlg, oGraph, oFont
   local aSales   := { 1000, 1200, 1300 }
   local aCosts   := {  700,  800, 1000 }

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 700,300 PIXEL TRUEPIXEL

   @ 40,40 GRAPH oGraph SIZE 600,200 PIXEL OF oDlg ;
      XVALUES YVALUES LEGENDS ;
      TYPE GRAPH_TYPE_BAR ;
      TITLE "Sales and Costs" ;
      FONT oFont

   oGraph:lViewVal   := .t.
   oGraph:nBarSep    := 10
   oGraph:AddSerie( aSales, "SALES", METRO_OLIVE )
   oGraph:AddSerie( aCosts, "COSTS", METRO_AMBER )
   oGraph:SetYVals( { "Jan", "Feb", "Mar" } )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
 
Image

Once you make one or two graphs, it will be very easy for you to use all extended capabilities of this class.

Re: FWH Graphs

Posted: Wed Oct 23, 2019 6:03 pm
by TimStone
Thank you.

I will start applying that today, and work through the graphs until I can eliminate the other code. I prefer, whenever possible, to stay within pure FWH.

Re: FWH Graphs

Posted: Wed Oct 23, 2019 6:45 pm
by TimStone
OK ... had a conflict with the other code but resolved it ... On my way. Thanks.

Re: FWH Graphs

Posted: Wed Oct 23, 2019 10:43 pm
by TimStone
What can I use to increase the size of the font used to display data on a pie chart ?

Re: FWH Graphs

Posted: Thu Oct 24, 2019 1:01 am
by nageswaragunupudi
Please see the method SetFonts( aFonts ) of TGraph class in tgraph.prg.

This class uses 9 fonts for 1) Title, 2) xFont, 3) yFont, 4) Legends, 5) Subtitle, 6) xTitle, 7) yTitle, 8 ) Values, 9) Values bold
You may set the font you want for values using :SetFonts( { nil, nil, nil, nil, nil, nil, nil, oValueFont, oValueBold } )

Re: FWH Graphs

Posted: Fri Oct 25, 2019 6:39 pm
by TimStone
All is good now. I have completed all the transitions, and removed the old graph software from my system.

Thank you.

Re: FWH Graphs

Posted: Sat Oct 26, 2019 10:32 am
by Marc Venken
TimStone wrote:All is good now. I have completed all the transitions, and removed the old graph software from my system.

Thank you.
Whaww.. So fast... easy transition ? Any sample screen ?

Re: FWH Graphs

Posted: Mon Oct 28, 2019 4:51 pm
by TimStone
Marc,

All of the data collection was valid, so instead of 30 or more lines of code, using Nages example, it was easy to build the new graphs with the calculated data ( which was already in the needed arrays ). As for screen shots, they are just like the sample Nages provided.

It took a bit over a day to redo about 20 graphs which is all I actually use right now.

Tim