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 |
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 |
Default() | Apply default chart settings and fonts |
Destroy() | Destroy the chart and free resources |
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.