FWH Graphs

FWH Graphs

Postby TimStone » Tue Oct 22, 2019 7:45 pm

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  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.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: FWH Graphs

Postby karinha » Tue Oct 22, 2019 7:52 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7801
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: FWH Graphs

Postby nageswaragunupudi » Wed Oct 23, 2019 3:39 am

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  Expand view
#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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH Graphs

Postby TimStone » Wed Oct 23, 2019 6:03 pm

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.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: FWH Graphs

Postby TimStone » Wed Oct 23, 2019 6:45 pm

OK ... had a conflict with the other code but resolved it ... On my way. Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: FWH Graphs

Postby TimStone » Wed Oct 23, 2019 10:43 pm

What can I use to increase the size of the font used to display data on a pie chart ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: FWH Graphs

Postby nageswaragunupudi » Thu Oct 24, 2019 1:01 am

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 } )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH Graphs

Postby TimStone » Fri Oct 25, 2019 6:39 pm

All is good now. I have completed all the transitions, and removed the old graph software from my system.

Thank you.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: FWH Graphs

Postby Marc Venken » Sat Oct 26, 2019 10:32 am

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 ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FWH Graphs

Postby TimStone » Mon Oct 28, 2019 4:51 pm

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
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests