Hello,
I have a dialog with a Listbox and a Tgraph .
When i select an other line in the Listbox, i 'd like to repopulate the graph with the values of other records .
How to change the values of the graph ?
Thanks
Hello,
I have a dialog with a Listbox and a Tgraph .
When i select an other line in the Listbox, i 'd like to repopulate the graph with the values of other records .
How to change the values of the graph ?
Thanks
Jack,
Could you provide a small example using your code ? This way we can modify it and show you how to do it, thanks! ![]()
Antonio,
I don't know how to change the array ASERIES .
Here is a sample of code :
*
REDEFINE LISTBOX oLbxta FIELDS ID 200 of oDlgrh
REDEFINE GRAPH oGraf OF odlgrh ID 300 TITLE "Evolution" XGRID YGRID XVALUES YVALUES LEGENDS TYPE 2
oGraf:cTitle := "Historique de "+trim(wrh->lib)
oGraf:cSubTit:= "Seconde zone de titre"
oGraf:cTitX := "Demandes"
oGraf:cTitY := "Valeurs"
* oGraf:lPopUp := .T.
oGraf:AddSerie(aSerie, "Valeurs", RGB(128,128,255))
oGraf:SetYVals(aLeyen)
oLbxta:bChange := { || oGraf:cTitle:=trim(wrh->lib),??? here to place the code to repopulate ???,oGraf:Refresh() }
ACTIVATE DIALOG oDlgrh CENTERED
The easiest way would be to just kill the entire graph object and build a new one. This is probably not the most efficient, however.
James
I just looked at the TGraph code and there are no methods to delete a series of data. Adding such a method would require a fair amount of programming.
James
Jack wrote:Hello,
I have a dialog with a Listbox and a Tgraph .
When i select an other line in the Listbox, i 'd like to repopulate the graph with the values of other records .
How to change the values of the graph ?
Thanks
#include "fivewin.ch"
#include "tgraph.ch"
REQUEST DBFCDX
function main()
local oDlg, oBrw, oGraph, oFont
CreateTestDBF() // Creates test DBF and opens with Alias "SC"
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 900,340 PIXEL FONT oFont ;
TITLE "XBROWSE LINKED GRAPH"
@ 10,10 XBROWSE oBrw SIZE 210,150 PIXEL OF oDlg ;
DATASOURCE "SC" AUTOCOLS ;
HEADERS "MONTH", "USA", "EUROPE", "ASIA", "USA", "EUROPE", "ASIA" ;
FASTEDIT LINES NOBORDER
WITH OBJECT oBrw
:lHScroll := .f.
:lVScroll := .f.
:nStretchCol := 1
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:bClrRowFocus := { || { CLR_BLACK, RGB(185,220,255) } }
:cEditPictures := "9,999"
:aCols[ 1 ]:cEditPicture := nil
:SetGroupHeader( "SALES", 2, 4 )
:SetGroupHeader( "COSTS", 5, 7 )
:bChange := { || oGraph:cTitY := SC->MONTH, ;
oGraph:aData := { { SC->USAS, SC->EUROS, SC->ASIAS }, ;
{ SC->USAC, SC->EUROC, SC->ASIAC } }, ;
oGraph:Refresh() }
AEval( :aCols, { |o| o:nEditType := EDIT_GET, ;
o:bOnChange := ;
{ |oc| oGraph:aData[ Int( ( oc:nCreationOrder - 2 ) / 3 ) + 1, ;
( oc:nCreationOrder - 2 ) % 3 + 1 ;
] := oc:Value, ;
oGraph:Refresh() } ;
}, 2 )
//
:CreateFromCode()
END
@ 10,220 GRAPH oGraph SIZE 200,150 PIXEL OF oDlg ;
TITLE "Sales and Costs" ;
XVALUES YVALUES TYPE GRAPH_TYPE_BAR LEGENDS
oGraph:cTitY := SC->MONTH
ADD SERIE TO oGraph SERIE { SC->USAS, SC->EUROS, SC->ASIAS } LEGEND "Sales" COLOR CLR_HRED
ADD SERIE TO oGraph SERIE { SC->USAC, SC->EUROC, SC->ASIAC } LEGEND "Costs" COLOR CLR_GREEN
SET Y LABELS OF oGraph TO { "USA", "EUROPE", "ASIA" }
oGraph:nMaxVal := 2000
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function CreateTestDBF()
local aCols := { ;
{ "MONTH", 'C', 3, 0 }, ;
{ "USAS", 'N', 4, 0 }, ;
{ "EUROS", 'N', 4, 0 }, ;
{ "ASIAS", 'N', 4, 0 }, ;
{ "USAC", 'N', 4, 0 }, ;
{ "EUROC", 'N', 4, 0 }, ;
{ "ASIAC", 'N', 4, 0 } }
local aData := { { "JAN", 1000, 1200, 900, 400, 700, 400 }, ;
{ "FEB", 1100, 1300, 1000, 500, 800, 500 }, ;
{ "MAR", 1050, 1800, 1900, 700, 1400, 1600 } ;
}
DBCREATE( "SALECOST.DBF", aCols, "DBFCDX", .t., "SC" )
FW_ArrayToDBF( aData )
GO TOP
return nil :bChange := { || oGraph:cTitY := SC->MONTH, ;
oGraph:aData := { { SC->USAS, SC->EUROS, SC->ASIAS }, ;
{ SC->USAC, SC->EUROC, SC->ASIAC } }, ;
oGraph:Refresh() }

WOW sensational
Best regards,
Otto
Great sample!
EMG
Thanks a lot ,
It is just what I was looking for !
Thanks


Mr Uwe
The second graph is very nice.
Can you please suggest revised code?
I modified the above code to provide for editing of values in the browse. When a value in the browse is modified, the corresponding value in the oGraph:aData is modified and the graph is refreshed.
My intention is to keep on record the possibilities of dynamic updating of TGraph.


// Back area
//
IF ! Empty( ::cBitmap ) .AND. File( AnsiToOem( Lfn2Sfn( ::cBitmap ) ) )
::SayBitmap( 0, 0, AnsiToOem( Lfn2Sfn( ::cBitmap ) ), ::nWidth, ::nHeight )
ELSEIF Empty( ::oPrn ) .AND. ::nType != GRAPH_TYPE_PIE
IF ::nDegrade = 1
::FillRect( nTop, nLeft, nBottom-nDeep, nRight, ::nClrBack )
ELSE
hBru = GradientBrush( ::hDC, 0, 0, 0, nBottom-nDeep, ;
{ { 0, ::nClrBack, LightColor(175,::nClrBack) } }, .T. )
FillRect( ::hDC,{ nTop, nLeft, nBottom-nDeep , nRight }, hBru )
ENDIF
ENDIF
// Back area
//
IF ! Empty( ::cBitmap ) .AND. File( AnsiToOem( Lfn2Sfn( ::cBitmap ) ) )
::SayBitmap( 0, 0, AnsiToOem( Lfn2Sfn( ::cBitmap ) ), ::nWidth, ::nHeight )
IF ::nDegrade = 1
::FillRect( nTop, nLeft, nBottom-nDeep, nRight, ::nClrBack )
ELSE
hBru = GradientBrush( ::hDC, 0, 0, 0, nBottom-nDeep, ;
{ { 0, ::nClrBack, LightColor(175,::nClrBack) } }, .T. )
FillRect( ::hDC,{ nTop, nLeft, nBottom-nDeep , nRight }, hBru )
ENDIF
ELSEIF Empty( ::oPrn ) .AND. ::nType != GRAPH_TYPE_PIE
IF ::nDegrade = 1
::FillRect( nTop, nLeft, nBottom-nDeep, nRight, ::nClrBack )
ELSE
hBru = GradientBrush( ::hDC, 0, 0, 0, nBottom-nDeep, ;
{ { 0, ::nClrBack, LightColor(175,::nClrBack) } }, .T. )
FillRect( ::hDC,{ nTop, nLeft, nBottom-nDeep , nRight }, hBru )
ENDIF
ENDIF