Drawing Graphs from file data
Posted: Tue Mar 05, 2019 10:06 am
Hi,
I am from Melbourne, Australia.
I have many years programming in Clipper mainly for my own use - databases for personal and financial details mainly.
I have made several HMG projects successively.
Current problem is a need to make a graph of price data from a DBF file.
I have tried the Bos Tauros samples but having lots of problems with the array functions in them.
The following code is a cut-down version of original - eg, I have eliminated the pie graph option, as well as 3D option etc. to simplify it a bit. Only a sample of the original array declaration works - all other versions do not work.
The other 3 code options all give same error message "DRAW GRAPH: 'Series' / 'SerieNames' / 'Colors' arrays size mismatch." from h_GraphBitmap.prg
I have looked through the many posts re 'BT graphing' but none seem to address the simple point that I am wanting - the ability to draw a graph from a series of datapoints contained in a DBF file.
/*
MINIGUI - Harbour Win32 GUI library Demo
Author: Siri Rathinagiri <srgiri@dataone.in>
Revised by Grigory Filatov <gfilatov@inbox.ru>
*/
#include "hmg.ch"
FUNCTION Main
set font to "Arial", 9
// altd()
define window graph at 0, 0 width 1000 height 700 title 'Bos Taurus Graph' main
define label selecttype
row 10
col 45
width 115
value 'Select Graph Type'
vcenteralign .T.
end label
define combobox graphtype
row 10
col 160
width 100
items { 'Bar', 'Lines', 'Points', 'Pie' }
onchange drawgraph()
end combobox
define checkbox enable3d
row 10
col 280
width 100
caption 'Enable 3D'
onchange drawgraph()
value .F.
end checkbox
define button Button_1
row 10
col 400
caption 'Save as PNG'
action ProcSaveGraph()
end button
define image grapharea
row 50
col 50
width 800
height 600
stretch .T.
end image
end window
graph.graphtype.value := 2
graph.center
graph.activate
RETURN NIL
FUNCTION drawgraph
LOCAL nImageWidth := graph.grapharea.width
LOCAL nImageHeight := graph.grapharea.height
LOCAL aSV := {}, aSN := {}
LOCAL hBitmap
LOCAL i := 0
IF graph.graphtype.value == 0
RETURN NIL
ENDIF
#define COLOR1 { 128, 128, 255 }
/*
// Option 1 : FOR-NEXT with simple arrays
FOR i = 1 to 5
AADD( aSV, 100+5*i )
AADD( aSN, "" )
NEXT
*/
// Option 2 : array with structure as per original. This is only option that works!
aSV := { { 105, 110, 115, 120, 125 } }
aSN := { "", "", "", "", "" }
/*
// Option 3 : simple array with 'normal' declaration
aSV := { 105, 110, 115, 120, 125 }
aSN := { "", "", "", "", "" }
*/
/*
// Option 4 : desired result - load data points from a DBF
use ( "BT_TEST.DBF" ) // just a DBF with numerics in first field
DO WHILE ! EOF()
AADD( aSV := FIELDGET( 1 ) )
AADD( aSN, "" )
SKIP
ENDDO
*/
GRAPH BITMAP graph.GraphType.VALUE ;
SIZE nImageWidth, nImageHeight ;
SERIEVALUES aSV ;
SERIENAMES { "Serie 1" } ;
SERIECOLORS { COLOR1 } ;
SERIEYNAMES aSN ;
PICTURE "99,999.99" ;
TITLE "Sample Graph" ;
TITLECOLOR BLACK ;
HVALUES 5 ;
BARDEPTH 15 ;
BARWIDTH 15 ;
SEPARATION NIL ;
LEGENDWIDTH 10 ;
3DVIEW .F. ;
SHOWGRID .T. ;
SHOWXGRID .T. ;
SHOWYGRID .T. ;
SHOWVALUES .F. ;
SHOWXVALUES .T. ;
SHOWYVALUES .T. ;
SHOWLEGENDS .T. ;
NOBORDER .F. ;
STOREIN hBitmap
graph.grapharea.HBITMAP := hBitmap // Assign hBitmap to the IMAGE control
RETURN NIL
PROCEDURE ProcSaveGraph()
LOCAL cFileName
LOCAL hBitmap := graph.grapharea.HBITMAP // Gets the value of hBitmap from the IMAGE control
IF hBitmap <> 0 .AND. graph.GraphType.VALUE > 0
cFileName := "Graph_" + graph.GraphType.ITEM( graph.GraphType.VALUE ) + IIF( graph.Enable3D.VALUE, "3D", "2D") + ".PNG"
BT_BitmapSaveFile( hBitmap, cFileName, BT_FILEFORMAT_PNG )
MsgInfo( "Save as: " + cFileName )
ENDIF
RETURN
I would be relieved to know there is a solution to this matter.
Prof50
I am from Melbourne, Australia.
I have many years programming in Clipper mainly for my own use - databases for personal and financial details mainly.
I have made several HMG projects successively.
Current problem is a need to make a graph of price data from a DBF file.
I have tried the Bos Tauros samples but having lots of problems with the array functions in them.
The following code is a cut-down version of original - eg, I have eliminated the pie graph option, as well as 3D option etc. to simplify it a bit. Only a sample of the original array declaration works - all other versions do not work.
The other 3 code options all give same error message "DRAW GRAPH: 'Series' / 'SerieNames' / 'Colors' arrays size mismatch." from h_GraphBitmap.prg
I have looked through the many posts re 'BT graphing' but none seem to address the simple point that I am wanting - the ability to draw a graph from a series of datapoints contained in a DBF file.
/*
MINIGUI - Harbour Win32 GUI library Demo
Author: Siri Rathinagiri <srgiri@dataone.in>
Revised by Grigory Filatov <gfilatov@inbox.ru>
*/
#include "hmg.ch"
FUNCTION Main
set font to "Arial", 9
// altd()
define window graph at 0, 0 width 1000 height 700 title 'Bos Taurus Graph' main
define label selecttype
row 10
col 45
width 115
value 'Select Graph Type'
vcenteralign .T.
end label
define combobox graphtype
row 10
col 160
width 100
items { 'Bar', 'Lines', 'Points', 'Pie' }
onchange drawgraph()
end combobox
define checkbox enable3d
row 10
col 280
width 100
caption 'Enable 3D'
onchange drawgraph()
value .F.
end checkbox
define button Button_1
row 10
col 400
caption 'Save as PNG'
action ProcSaveGraph()
end button
define image grapharea
row 50
col 50
width 800
height 600
stretch .T.
end image
end window
graph.graphtype.value := 2
graph.center
graph.activate
RETURN NIL
FUNCTION drawgraph
LOCAL nImageWidth := graph.grapharea.width
LOCAL nImageHeight := graph.grapharea.height
LOCAL aSV := {}, aSN := {}
LOCAL hBitmap
LOCAL i := 0
IF graph.graphtype.value == 0
RETURN NIL
ENDIF
#define COLOR1 { 128, 128, 255 }
/*
// Option 1 : FOR-NEXT with simple arrays
FOR i = 1 to 5
AADD( aSV, 100+5*i )
AADD( aSN, "" )
NEXT
*/
// Option 2 : array with structure as per original. This is only option that works!
aSV := { { 105, 110, 115, 120, 125 } }
aSN := { "", "", "", "", "" }
/*
// Option 3 : simple array with 'normal' declaration
aSV := { 105, 110, 115, 120, 125 }
aSN := { "", "", "", "", "" }
*/
/*
// Option 4 : desired result - load data points from a DBF
use ( "BT_TEST.DBF" ) // just a DBF with numerics in first field
DO WHILE ! EOF()
AADD( aSV := FIELDGET( 1 ) )
AADD( aSN, "" )
SKIP
ENDDO
*/
GRAPH BITMAP graph.GraphType.VALUE ;
SIZE nImageWidth, nImageHeight ;
SERIEVALUES aSV ;
SERIENAMES { "Serie 1" } ;
SERIECOLORS { COLOR1 } ;
SERIEYNAMES aSN ;
PICTURE "99,999.99" ;
TITLE "Sample Graph" ;
TITLECOLOR BLACK ;
HVALUES 5 ;
BARDEPTH 15 ;
BARWIDTH 15 ;
SEPARATION NIL ;
LEGENDWIDTH 10 ;
3DVIEW .F. ;
SHOWGRID .T. ;
SHOWXGRID .T. ;
SHOWYGRID .T. ;
SHOWVALUES .F. ;
SHOWXVALUES .T. ;
SHOWYVALUES .T. ;
SHOWLEGENDS .T. ;
NOBORDER .F. ;
STOREIN hBitmap
graph.grapharea.HBITMAP := hBitmap // Assign hBitmap to the IMAGE control
RETURN NIL
PROCEDURE ProcSaveGraph()
LOCAL cFileName
LOCAL hBitmap := graph.grapharea.HBITMAP // Gets the value of hBitmap from the IMAGE control
IF hBitmap <> 0 .AND. graph.GraphType.VALUE > 0
cFileName := "Graph_" + graph.GraphType.ITEM( graph.GraphType.VALUE ) + IIF( graph.Enable3D.VALUE, "3D", "2D") + ".PNG"
BT_BitmapSaveFile( hBitmap, cFileName, BT_FILEFORMAT_PNG )
MsgInfo( "Save as: " + cFileName )
ENDIF
RETURN
I would be relieved to know there is a solution to this matter.
Prof50