Working with Graphics

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
Vanguarda
Posts: 543
Joined: Wed Feb 11, 2009 10:56 am
Location: Americana - SP
Contact:

Working with Graphics

Post by Vanguarda »

Hi all brothers,

I (trying) working with function DRAW GRAPH, but i´m not make it very well. Please see the error that i´m get in my function (attach).

See bellow my source too.

Code: Select all

*----------------------------------------------------------------------------------------*
Function Gerar_Grafico(c_String) //Esta função e reponsável por gerar o gráfico
*----------------------------------------------------------------------------------------*
      Local d_DataINI //Data Inicial
      Local d_DataFIN //Data Final
      Local c_Assunto //Assunto à filtrar
      Local c_Area    //Area admistrativa ou pedagógica
      Local c_Curso   //Curso à filtrar
      Local a_Titulos := {"Coordenadores","Professores","Monitores",;
                          "Laboratório","Coordenação","Limpeza","Xerox",;
                          "Biblioteca","SAE","Gerais","Inspetores",;
                          "Portaria","Cantina"} //Array de títulos da legenda
      Local a_Valores := {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}} //Array que conterá os valores da legenda
      Local a_Cores   := { {128,128,255}, {255,102, 10}, {55,201, 48},; 
                           {128,128,255}, {255,102, 10}, {55,201, 48},;
                           {128,128,255}, {255,102, 10}, {55,201, 48},;
                           {128,128,255}, {255,102, 10}, {55,201, 48},;
                           {128,128,255} } //Array que conterá as cores da legenda e gráfico
      Local a_Result  //Array que conterá o resultado da QUERY SQL
      Local n_V    := n_H := 1 //Contador local Vertical e horizontal
      
      DECLARE WINDOW GRAFICO // declara o form gráfico neste módulo para poder-mos usar os objetos do mesmo
      
     if Grafico.DatePicker_1.Value > Grafico.DatePicker_2.Value
        Mensagem("Data inicial não pode ser maior que a data final!")
        Return
     endif
     
     a_Result := Get_PSQ(c_String,Grafico.DatePicker_1.Value,Grafico.DatePicker_2.Value)

     if empty(a_Result[1][1])
        Mensagem("Não foram encontrados registros com este período!")
        Return
     endif
     
     while(n_V <= Len(a_Result))        
       if a_Result[n_V][1] >= Grafico.DatePicker_1.Value
          if a_Result[n_V][1] <= Grafico.DatePicker_2.Value
             a_Valores[01][1] := a_Valores[01][1]+a_result[n_V][02]
             a_Valores[02][1] := a_Valores[02][1]+a_result[n_V][03]
             a_Valores[03][1] := a_Valores[03][1]+a_result[n_V][04]
             a_Valores[04][1] := a_Valores[04][1]+a_result[n_V][05]
             a_Valores[05][1] := a_Valores[05][1]+a_result[n_V][06]
             a_Valores[06][1] := a_Valores[06][1]+a_result[n_V][07]
             a_Valores[07][1] := a_Valores[07][1]+a_result[n_V][08]
             a_Valores[08][1] := a_Valores[08][1]+a_result[n_V][09]
             a_Valores[09][1] := a_Valores[09][1]+a_result[n_V][10]
             a_Valores[10][1] := a_Valores[10][1]+a_result[n_V][11]
             a_Valores[11][1] := a_Valores[11][1]+a_result[n_V][12]             
             a_Valores[12][1] := a_Valores[12][1]+a_result[n_V][13]             
             a_Valores[13][1] := a_Valores[13][1]+a_result[n_V][14]                          
          endif
       endif
       n_V++
     enddo
   Grafico.HIDE
   
   Load window Grafico2
   Grafico2.Center
   Grafico2.Activate
   
  // ERASE WINDOW Grafico2

   DRAW GRAPH                     ;
      IN WINDOW Grafico2               ;
      AT 20,20                  ;
      TO 400,610                  ;
      TITLE "Estatístca de satisfação"            ;
      TYPE BARS                  ;
      SERIES a_Valores                  ;
      YVALUES a_Titulos         ;
      DEPTH 30                  ;
      BARWIDTH 30                  ;
      HVALUES 13                  ;
      SERIENAMES a_Titulos      ;
      COLORS a_Cores   ;
      3DVIEW                      ;
      SHOWGRID     ;
      SHOWXVALUES  ;
      SHOWYVALUES  ;
      SHOWLEGENDS  ;
      NOBORDER
     
Return
I not understood about this very well, i can find it in my HMG doc but it not is explained much.

I thanks for help me,


with best regards,
Attachments
Erro.JPG
Erro.JPG (31.42 KiB) Viewed 5792 times
--
Paulo Sérgio Durço (Vanguarda)


http://hmglights.wordpress.com/
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Working with Graphics

Post by sudip »

Hi Vanguarda,

I created an add-on application with HMG for my old xHarbour+gtwvw app (where I first found problem of Pie, which was first corrected by Esgici). Following is a part of that program :-

(Please note that following code contains some user defined functions which are not so important for graph.)

Code: Select all

#include "minigui.ch"
#include "datadict.ch"

#define	CALC_RS	1
#define	CALC_CS	2

#define AMT_AFTER_VAT   round((qty*iif(rtincs, rate/item->incase, rate)-(cstrld+discamt))*(1+taxrate/100), 2)

static aProdcd, aProdnm, aMonth

Function PurSaleGraph

	CreateLookup()

	Define Window frmPG ;
		at 0, 0 ;
		width 470 ;
		height 350 ;
		title "Purchase vs Sale Graph" ;
		CHILD ;
		nomaximize ;
		on init {|| frmPG.progress_1.hide() }
		

		@ 30, 10 label lblPrid value "Product Group:"
		@ 30, 110 combobox cboProdcd ;
			items aProdnm ;
			width 200
		@ 30, 350 button cmdAllprod caption "All Products" on click {|| setproperty('frmPG', 'cboProdcd', 'value', 0)}
		
		@ 180, 10 label lblCalcon value "Calculate on:"
		@ 180, 110 combobox cboCalcon ;
			value CALC_RS ;
			items {"Rupees", "Cases"} 

		@ 240, 350 button cmdRun caption "Generate Graph" ;
			action CalculateGraph()
			
		@ 240, 10 PROGRESSBAR Progress_1 ;
			RANGE 0,100 ;
			WIDTH 300 HEIGHT 26 ;

											
	end window
	
	frmPG.center
	frmPG.activate
return nil


STATIC FUNCTION CreateLookup()
   local i
   
   aProdcd := {}
   aProdnm := {}
   
   netselect("prod")
   set order to 2
   dbeval({|| aadd(aProdcd, prod->prodcd), aadd(aProdnm, prod->prodnm)})
      
   return nil
		


   
   
STATIC function CalculateGraph()
	local mProdcd, i, n, t, ;
		ax1, ax2, ay, aSer, mGraphTitle
		
	store 0 to mAreacd, mcrdtrcd, mSmancd, mProdcd, lAmtwise
	
	lAmtwise := (frmPG.cboCalcon.value == CALC_RS)
	
	if !empty(frmPG.cboProdcd.value)
		mProdcd := aProdcd[frmPG.cboProdcd.value]
	endif

	aMonth := {{"Apr", 0.00, 0.00}, {"May", 0.00, 0.00}, {"Jun", 0.00, 0.00}, ;
   	{"Jul", 0.00, 0.00}, {"Aug", 0.00, 0.00}, {"Sep", 0.00, 0.00}, ;
   	{"Oct", 0.00, 0.00}, {"Nov", 0.00, 0.00}, {"Dec", 0.00, 0.00}, ;
   	{"Jan", 0.00, 0.00}, {"Feb", 0.00, 0.00}, {"Mar", 0.00, 0.00}}
   	
   netselect("item")
   set order to 1
   
   netselect("stock")
   set order to 1
   set relation to "F"+str(itemcd, 4) into item additive
   t := reccount()
   n := 0
   go top
   frmPG.progress_1.value := 0
   frmPG.progress_1.show()
   do while !eof()
   	n++
   	frmPG.progress_1.value := n/t*100
   	
   	if !(doctype = CRPUR .or. doctype = GENSALE) .or. ;
   		(!empty(mProdcd) .and. item->prodcd != mProdcd)
   		
   		skip
   		loop
   	endif
   	
   	mVal := iif(lAmtwise, AMT_AFTER_VAT, qty/item->incase)
   	
   	i = month(docdt)-3
   	if i < 1
   		i = 12 + i
   	endif
   	
   	if doctype = CRPUR
   		aMonth[i, 2] += mVal
   	else
		aMonth[i, 3] += mVal
	endif   	
   	
   	skip
   enddo
   
   netselect("stock")
   set relation to
	
   frmPG.progress_1.hide()
   
   ax1 := {}
   ax2 := {}
   ay := {}
   
  // aeval(aMonth, {|i| aadd(ax, aMonth[i, 2]), aadd(ay, aMonth[i, 1])})
   for i := 1 to len(aMonth)
   	aadd(ax1, round(aMonth[i, 2]/iif(lAmtwise, 1000, 1), 2))
   	aadd(ax2, round(aMonth[i, 3]/iif(lAmtwise, 1000, 1), 2))
   	aadd(ay, aMonth[i, 1])
   next

   aSer := {}
   aadd(aSer, ax1)
   aadd(aSer, ax2)   
   
   mGraphTitle := iif(lAmtwise, "Purchase vs Sale (in thousand Rs.)", "Purchase vs Sale (qty in cases)")
   
   GenerateGraph(aSer, ay, mGraphTitle)
   
  return nil
	

  
static Function GenerateGraph(aSer, ay, mGraphTitle)

	Define Window GraphTest ;
		At 0,0 ;
		Width 640 ;
		Height 480 ;
		Title "Graph" ;
		MODAL ;
		BackColor { 255 , 255 , 255 } ;
		On Init DrawGraph ( 1, aSer, ay, mGraphTitle )
		
		@ 415, 20 label lblGraphtype value "Graph Type:" TRANSPARENT
		@ 415, 120 combobox cboGraphtype ;
			items {"Bars", "Lines", "Points"} ;
			value 1 ;
			on change DrawGraph(this.value, aSer, ay, mGraphTitle) 

		@ 415, 500 button cmdPrint caption "Print" ;
			Action PRINT GRAPH OF GraphTest PREVIEW DIALOG

	End Window

	GraphTest.Center

	Activate Window GraphTest

Return




static Procedure DrawGraph ( mGraphType, aSer, ay, mGraphTitle ) 

	ERASE WINDOW GraphTest
	
	if mGraphtype = 1
		DRAW GRAPH							;
			IN WINDOW GraphTest					;
			AT 20,20						;
			TO 400,610						;
			TITLE mGraphTitle				;
			TYPE BARS						;
			SERIES aSer					;
			YVALUES ay			;
			DEPTH 15						;
			BARWIDTH 15						;
			HVALUES 5						;
			SERIENAMES {"Purchase", "Sale"}		;
			COLORS { {255,0,0}, {128,128,255} }	;
			3DVIEW    						;
			SHOWGRID                        			;
			SHOWXVALUES                     			;
			SHOWYVALUES                     			;
			SHOWLEGENDS 						;
		NOBORDER
	elseif mGraphtype = 2
		DRAW GRAPH							;
			IN WINDOW GraphTest					;
			AT 20,20						;
			TO 400,610						;
			TITLE mGraphTitle				;
			TYPE LINES					;
			SERIES aSer					;
			YVALUES ay			;
			DEPTH 15						;
			BARWIDTH 15						;
			HVALUES 5						;
			SERIENAMES {"Purchase", "Sale"}		;
			COLORS { {255,0,0}, {128,128,255} }	;
			3DVIEW    						;
			SHOWGRID                        			;
			SHOWXVALUES                     			;
			SHOWYVALUES                     			;
			SHOWLEGENDS 						;
			NOBORDER
	else
			DRAW GRAPH							;
			IN WINDOW GraphTest					;
			AT 20,20						;
			TO 400,610						;
			TITLE mGraphTitle				;
			TYPE POINTS						;
			SERIES aSer					;
			YVALUES ay			;
			DEPTH 15						;
			BARWIDTH 15						;
			HVALUES 5						;
			SERIENAMES {"Purchase", "Sale"}		;
			COLORS { {255,0,0}, {128,128,255} }	;
			3DVIEW    						;
			SHOWGRID                        			;
			SHOWXVALUES                     			;
			SHOWYVALUES                     			;
			SHOWLEGENDS 						;
			NOBORDER
	endif
	
Return
  	
Hope this will be helpful to you.

With best regards.

Sudip
With best regards,
Sudip
User avatar
Vanguarda
Posts: 543
Joined: Wed Feb 11, 2009 10:56 am
Location: Americana - SP
Contact:

Re: Working with Graphics

Post by Vanguarda »

Hi sudip,

Thank for your help, this code will be very helpful for me.

Best regards,
--
Paulo Sérgio Durço (Vanguarda)


http://hmglights.wordpress.com/
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Working with Graphics

Post by esgici »

Hola Paulo

Does your problem solved ?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Vanguarda
Posts: 543
Joined: Wed Feb 11, 2009 10:56 am
Location: Americana - SP
Contact:

Re: Working with Graphics

Post by Vanguarda »

Hi friends

Hi Sudip, once more thank you for your code, was very useful for me.

Hi my friend esgici,
My problem is solved, thank your attention too.

Please friends, see bellow a Screen of my graphic run
Attachments
graph.JPG
graph.JPG (59.54 KiB) Viewed 5674 times
--
Paulo Sérgio Durço (Vanguarda)


http://hmglights.wordpress.com/
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Working with Graphics

Post by sudip »

Hi Vanguarda,

I am very happy to see the output of your graph generation software :D

HMG Graphics library was created by Rathinagiri.

So, thanks a lot to you, Rathi :D

Regards.

Sudip
With best regards,
Sudip
User avatar
Vanguarda
Posts: 543
Joined: Wed Feb 11, 2009 10:56 am
Location: Americana - SP
Contact:

Re: Working with Graphics

Post by Vanguarda »

Hi friends,

I´m very happy too for this graph.

Thank a lot, Rathi for your amazing LIB, it is very very useful for all us.

with best regards,
--
Paulo Sérgio Durço (Vanguarda)


http://hmglights.wordpress.com/
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Working with Graphics

Post by gfilatov »

sudip wrote:...
HMG Graphics library was created by Rathinagiri.

So, thanks a lot to you, Rathi :D
Hi Sudip,

FYI Please be so kind to take a look for the following description in the file hmg\source\graph\h_graph.prg:
/*
File: h_graph.prg
Author: Grigory Filatov / Rathinagiri (Pie Graph)
Description:
Status: Public Domain
Notes: Support function for DRAW commands

Based on works of:

Alfredo Arteaga 14/10/2001 original idea
Alfredo Arteaga TGRAPH 2, 12/03/2002
*/
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Working with Graphics

Post by sudip »

Sorry Grigory,
It's my careless mistake. Please forgive me :(
Regards.
Sudip
With best regards,
Sudip
User avatar
Vanguarda
Posts: 543
Joined: Wed Feb 11, 2009 10:56 am
Location: Americana - SP
Contact:

Re: Working with Graphics

Post by Vanguarda »

Hi friends,

I´m very happy too for this graph.

Thank a lot, Grigory for your amazing LIB, it is very very useful for all us.

with best regards,
--
Paulo Sérgio Durço (Vanguarda)


http://hmglights.wordpress.com/
Post Reply