TGraph
Source: source/classes/tgraph.prg
Inherits from: TControl
TGraph is FiveWin's charting control that supports bar, line, point, pie, and XY scatter charts. It provides a comprehensive set of graphing capabilities directly within FiveWin windows and dialogs, with support for multiple series, 3D rendering, legends, grid lines, and export to image or printer.
Graph Types
TGraph supports the following chart types, defined as numeric constants:
| Constant | Value | Description |
|---|---|---|
GRAPH_TYPE_BAR | 1 | Vertical bar chart (default) |
GRAPH_TYPE_LINE | 2 | Line chart connecting data points |
GRAPH_TYPE_POINT | 3 | Scatter/point chart |
GRAPH_TYPE_PIE | 4 | Pie chart |
GRAPH_TYPE_XY_LINES | 6 | XY scatter chart with connecting lines |
GRAPH_TYPE_XY_POINTS | 7 | XY scatter chart with points only |
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nType | Numeric | Graph type (GRAPH_TYPE_BAR, GRAPH_TYPE_LINE, etc.) |
aSeries | Array | Array of series definition objects |
aData | Array | Chart data values |
l3D | Logical | Enable 3D rendering |
lxGrid | Logical | Show X-axis grid lines |
lyGrid | Logical | Show Y-axis grid lines |
lxVal | Logical | Show X-axis value labels |
lyVal | Logical | Show Y-axis value labels |
cTitle | Character | Main chart title |
cSubTit | Character | Chart subtitle |
cTitX | Character | X-axis title |
cTitY | Character | Y-axis title |
cPicture | Character | Picture mask for value formatting |
lViewVal | Logical | Show data values on chart |
lLegends | Logical | Show series legends |
nBarSep | Numeric | Bar separation gap |
nPoint | Numeric | Point marker type (POINT_TYPE_1..3) |
nMaxVal | Numeric | Maximum Y-axis value |
nMinVal | Numeric | Minimum Y-axis value |
nClrBack | Numeric | Background color |
cBitmap | Character | Background bitmap file |
lAutoRefresh | Logical | Auto-repaint on data changes (.T. by default) |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, oWnd, nWidth, nHeight, cTitle, lDesign, lPixel, l3D, lxGrid, lyGrid, lxVal, lyVal, lPopUp, lLegends, nType ) | Create a new TGraph control |
ReDefine( nId, oWnd, cTitle, l3D, lxGrid, lyGrid, lxVal, lyVal, lPopUp, lLegends, nType ) | Redefine from dialog resource |
AddSerie( aDat, cLegend, nColor, nType, l3D, lViewVal, lDrawPoint, lDrawLine, cSRLegend ) | Add a data series to the chart. Returns the series index. |
AddXYSerie( aDat, cLegend, nColor, nType, l3D, lViewVal, lDrawPoint, lDrawLine, cSRLegend ) | Add an XY scatter series (array of {x,y} pairs) |
SetYVals( aLabels ) | Set Y-axis category labels (e.g., Q1, Q2, Q3, Q4) |
SelSerie( nSerie ) | Select a specific series for display |
SelPeriod( nPeriod ) | Select a specific period for display |
SaveAsImage( cFile ) | Save chart as a bitmap image file |
Save2XLS( nTypeGraph ) | Export chart data to Excel |
Print( oPrn, nTop, nLeft, nWidth, nHeight ) | Print the chart on a printer device |
PrintGraph( lPrev, oPrn, nY, nX, cFile, nPorY, nPorX, lUser, lHoriz, nTypePage ) | Advanced printing with preview and zoom options |
Copy2ClipBoard( lMsg ) | Copy chart image to clipboard |
ResizeSerie( nNewSize ) | Resize the number of series dynamically |
SetValue( nSerie, nPos, nValue, lRefresh ) | Change one value and repaint automatically |
GetValue( nSerie, nPos ) | Read one chart value |
SetData( aData, lRefresh ) | Replace all chart data and repaint automatically |
SetSerieValues( nSerie, aValues, lRefresh ) | Replace one series and repaint automatically |
SetXYValue( nSerie, nPos, xVal, yVal, lRefresh ) | Change one XY point and repaint automatically |
SetXYData( aXYValues, lRefresh ) | Replace all XY data and repaint automatically |
DelSerie( nSerie, lRefresh ) | Delete a series and repaint automatically |
ClearSeries( lRefresh ) | Delete all series and repaint automatically |
BeginUpdate() | Open an update block: repaints are deferred |
EndUpdate( lRefresh ) | Close the block and repaint once |
DoRefresh() | Repaint now (honors lAutoRefresh and update blocks). Alias: Update() |
Default() | Apply default chart settings and fonts |
Destroy() | Destroy the chart and free resources |
Auto-Refresh
With lAutoRefresh set (.T. by default), every data change
repaints the chart by itself — no need to rebuild the control or call
Refresh() manually. Change metrics while navigating and the
graph follows:
// One value changes -> the chart repaints itself
oGraph:SetValue( 1, 3, 1250 )
// Replace a whole series at once
oGraph:SetSerieValues( 2, { 10, 20, 30, 25, 40 } )
// Batch many changes with a single repaint at the end
oGraph:BeginUpdate()
oGraph:cTitle := "New title"
oGraph:SetData( { aVals1, aVals2 } )
oGraph:EndUpdate()
// Suspend automatic repaints and refresh manually
oGraph:lAutoRefresh := .F.
...
oGraph:Update()
Sample samples/graphics/graphkpi.prg shows the pattern in a
full window: two TXBrowse controls with KPI columns and footer totals, a
docked buttonbar, a statusbar with the selected KPIs, and a
splitter-resizable TGraph that repaints itself while browsing or when the
metrics change. Note: code-created browses need
oBrw:CreateFromCode(), and direct assignments to
::aData / ::aSeries cannot be intercepted — use
the Set*() methods or call Refresh() afterwards.
Example: Bar Chart with Two Series
#include "FiveWin.ch"
function Main()
local oWnd, oGraph
DEFINE WINDOW oWnd TITLE "Quarterly Sales" SIZE 600, 400
@ 10, 10 GRAPH oGraph SIZE 560, 340 OF oWnd TYPE GRAPH_TYPE_BAR ;
TITLE "Sales by Quarter"
oGraph:l3D := .T.
oGraph:lxGrid := .T.
oGraph:lyGrid := .T.
oGraph:lxVal := .T.
oGraph:lyVal := .T.
oGraph:lLegends := .T.
oGraph:cPicture := "999,999.99"
// Set category labels
oGraph:SetYVals( { "Q1", "Q2", "Q3", "Q4" } )
// Add two series
oGraph:AddSerie( { 1200, 1500, 1100, 1800 }, "Product A", CLR_RED )
oGraph:AddSerie( { 900, 1300, 1600, 1400 }, "Product B", CLR_BLUE )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TGraph is a fully self-contained charting engine that does not rely on external ActiveX or OCX components. All rendering is done via GDI.
- Use
GRAPHcommand syntax withTYPE nTypeto set the chart type at creation time. - Colors for series are auto-assigned from an internal palette if not specified. The default palette cycles through METRO_AMBER, METRO_OLIVE, CLR_HMAGENTA, CLR_HBLUE, CLR_HRED, CLR_HGREEN, and standard colors.
- XY charts (types 6 and 7) expect data as arrays of
{ x, y }coordinate pairs. UseAddXYSerie()to add XY series. - Export to image uses
Save2Bmp()internally. The chart can also be copied to clipboard for pasting into other applications. - The popup menu (enabled via
lPopUp) provides right-click access to chart type switching, grid toggles, and export options at runtime. - Direct assignments to
::aData/::aSeriesdo not repaint: use theSet*()methods or callRefresh()afterwards.