#include "FiveWin.ch"
#include "constant.ch"
Function Grafico()
local oBar, oCol, oCont,oOptions
local aBrowse
local i,oLogoBmp,oCursor
LOCAL oBrush := TBrush():New("NULL",,,)
Local aMes:={ "Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Oct","Nov","Dic" }
Local aEntrate :={}
Local aUscite :={}
Local nBottom := 45
Local nRight := 120
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local cClrEntrate := 7031871
Local cClrUscite := 204
Local nMaxValGraph := 2000
Local aCanE :={ { "Gen", 0 }, { "Feb", 0 }, { "Mar", 0 }, { "Apr", 0 }, ;
{ "Mag", 0 }, { "Giu", 0 }, { "Lug", 0 }, { "Ago", 0 }, ;
{ "Set", 0 }, { "Oct", 0 }, { "Nov", 0 }, { "Dic", 0 } }
Local aCanU :={ { "Gen", 0 }, { "Feb", 0 }, { "Mar", 0 }, { "Apr", 0 }, ;
{ "Mag", 0 }, { "Giu", 0 }, { "Lug", 0 }, { "Ago", 0 }, ;
{ "Set", 0 }, { "Oct", 0 }, { "Nov", 0 }, { "Dic", 0 } }
USE MOVIMENTI ALIAS MV
SELECT MV
MV->(DbGoTop())
MV->( DBEVAL( { || IF(Month( FIELD->APFECHA ) >0, aCanE[ Month( FIELD->APFECHA ) ][ 2 ]+= IIF( FIELD->APTIPO="E", MV->APIMPTOTAL,0), ) }) )
MV->( DBEVAL( { || IF(Month( FIELD->APFECHA ) >0, aCanU[ Month( FIELD->APFECHA ) ][ 2 ]+= IIF( FIELD->APTIPO="U", MV->APIMPTOTAL,0), ) }) )
For n=1 to len( aCanE)
AADD( aEntrate,aCanE[n][2])
next n
For n=1 to len( aCanU)
AADD( aUscite,aCanU[n][2])
next n
DEFINE DIALOG oDlg ;
TITLE "Test New Graph" ;
SIZE nWidth, nHeight TRANSPARENT PIXEL
oGraph:=TGraph():New(0,0,oDlg,oDlg:nBottom/2,oDlg:nWidth/4)
oGraph:cPicture:="99,999.99"
oGraph:SetYVals(aMes)
oGraph:nType :=1
oGraph:cTitX :="Importo Totale"
oGraph:cTitY :="Mesi"
oGraph:lYVal :=.T.
oGraph:lLegends:=.T.
oGraph:lPopUp :=.F.
oGraph:nBarD :=15
oGraph:nXRanges:=20
oGraph:l3D :=.f.
oGraph:nBarSep:=5
oGraph:lxGrid :=.T.
oGraph:lYGrid :=.f.
oGraph:cTitle:="Visualizzazione annuale dei movimenti di entrata ed uscita"
oGraph:AddSerie(aEntrate,"Entrate",cClrEntrate)
oGraph:AddSerie(aUscite,"Uscite",cClrUscite)
oGraph:cToolTip = { | nAt | Str( nAt ) }
ACTIVATE DIALOG oDlg
return nil
// Add
DATA lToolTip // Default = FALSE
//-------------------------------
// To display tooltip
oGraph:lToolTip := TRUE
oGraph:cToolTip = { | nAt, nRow, nCol | oGraph:ToolTip( nAt, nRow, nCol) }
//--------------------------------------------------
METHOD ToolTip(nAt, nRow, nCol) CLASS TGRAPH
// Display Tootip for one or two value series
if nAt/2 - int(nAt/2) = 0
// Even (Series 2)
nI := nAt/2
::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::cLabelSerie2 + " = $"+ ::aSeries2[nI] )
else
// Odd (Series 1)
nI := int(nAt/2)+1
::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::cLabelSerie1 + " = " + ::aSeries1[nI] )
endif
//------------------------------------------------------------------------
METHOD MouseMove( nRow, nCol, nFlags ) CLASS TGraph
LOCAL nAt := 0
if ::lToolTip = .T.
if ! Empty( ::aBarCoors )
nAt = AScan( ::aBarCoors,;
{ | aCoors | nRow <= aCoors[ 2 ] .and. ;
nRow >= aCoors[ 2 ] - aCoors[ 3 ] .and. ;
nCol >= aCoors[ 1 ] .and. ;
nCol <= aCoors[ 1 ] + aCoors[ 4 ] } )
if nAt != 0
DEFAULT ::cToolTip := { | nAt | AllTrim( Transform( ::aData[ 1 ][ nAt ],;
"999,999,999.99" ) ) }
//::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt ) )
::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt, nRow, nCol ) )
else
::DestroyTooltip()
endif
endif
endif
return nil
return (.T.)
oGraph:cToolTip = { | nAt, nSerie | nSerie := If( nAt % ;
Len( oGraph:aSeries ) == 0, Len( oGraph:aSeries ),;
Int( nAt % Len( oGraph:aSeries ) ) ),;
"Series: " + Alltrim( Str( nSerie ) ) + CRLF + ;
"Bar: " + AllTrim( Str( Int( nAt / Len( oGraph:aSeries ) ) + 1 + ;
If( nAt % Len( oGraph:aSeries ) == 0, -1, 0 ) ) ) }
METHOD AddSerie( aDat, cLegend, nColor, nType, l3D ) CLASS TGraph
LOCAL nI
DEFAULT nType := NIL, ;
l3D := NIL
AAdd( ::aSeries, { cLegend, nColor, nType, l3D } )
AAdd( ::aData , aDat )
AAdd( ::aSTemp , { cLegend, nColor, nType, l3D } )
AAdd( ::aDTemp, aDat )
// Coded added
IF len( ::aSeries ) = 1
// Series 1
FOR nX := 1 TO LEN(aDat)
aadd(::aSeries1, transform(int(aDat[nX]), "@B 999,999" ) )
NEXT
::cLabelSerie1 := ::aSeries[len( ::aSeries )] [1]
ELSE
// Series 2
FOR nX := 1 TO LEN(aDat)
aadd(::aSeries2, transform(int(aDat[nX]*100), "@B 999,999,999" ))
NEXT
::cLabelSerie2 := ::aSeries[len( ::aSeries )] [1]
ENDIF
RETURN Len( ::aSeries )
//---------------------------------------------------------------------------
// To use Tooltips in TGRAPH Class (only tested with one and two series!)
//---------------------------------------------------------------------------
// In your program
oGraph:lToolTip := TRUE
oGraph:cToolTip = { | nAt, nSerie, nRow, nCol | nSerie := If( nAt % ;
Len( oGraph:aSeries ) == 0, Len( oGraph:aSeries ),;
Int( nAt % Len( oGraph:aSeries ) ) ),;
oGraph:ToolTip( nAt, nRow, nCol, nSerie) }
//--------------------------------------------------------
// Data to be added to TGRAPH Class
//-----------------------------------------------------
DATA aBarCoors
DATA lToolTip INIT .F.
//------------------------------------------------------------------------
// Methods to add in TGRAPH Class
//------------------------------------------------------------------------
METHOD MouseMove( nRow, nCol, nFlags ) CLASS TGraph
LOCAL nAt := 0
if ::lToolTip = .T.
if ! Empty( ::aBarCoors )
nAt = AScan( ::aBarCoors,;
{ | aCoors | nRow <= aCoors[ 2 ] .and. ;
nRow >= aCoors[ 2 ] - aCoors[ 3 ] .and. ;
nCol >= aCoors[ 1 ] .and. ;
nCol <= aCoors[ 1 ] + aCoors[ 4 ] } )
if nAt != 0
::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt, nRow, nCol ) )
else
::DestroyTooltip()
endif
endif
endif
return nil
//-------------------------------------------------------------------------
METHOD ToolTip(nAt, nRow, nCol, nSerie) CLASS TGRAPH
LOCAL nSeries := len(::aSeries), nI
if nSeries = 1
::ShowToolTip( nRow, nCol, ::aYVals[nAt] + CRLF+ ::aSeries[1][1] + " = " + alltrim(str(::aData[1][nAT])))
elseif nAt/2 - int(nAt/2) = 0
// Even
nI := int(nAt/nSeries)
::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::aSeries[nSerie][1] + " = " + alltrim(str(::aData[nSerie][nI])) )
else
// Odd
nI := int(nAt/nSeries) + 1
::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::aSeries[nSerie][1] + " = " + alltrim(str(::aData[nSerie][nI])) )
endif
return nil
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 34 guests