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:

ConstantValueDescription
GRAPH_TYPE_BAR1Vertical bar chart (default)
GRAPH_TYPE_LINE2Line chart connecting data points
GRAPH_TYPE_POINT3Scatter/point chart
GRAPH_TYPE_PIE4Pie chart
GRAPH_TYPE_XY_LINES6XY scatter chart with connecting lines
GRAPH_TYPE_XY_POINTS7XY scatter chart with points only

Key DATA Members

DATATypeDescription
nTypeNumericGraph type (GRAPH_TYPE_BAR, GRAPH_TYPE_LINE, etc.)
aSeriesArrayArray of series definition objects
aDataArrayChart data values
l3DLogicalEnable 3D rendering
lxGridLogicalShow X-axis grid lines
lyGridLogicalShow Y-axis grid lines
lxValLogicalShow X-axis value labels
lyValLogicalShow Y-axis value labels
cTitleCharacterMain chart title
cSubTitCharacterChart subtitle
cTitXCharacterX-axis title
cTitYCharacterY-axis title
cPictureCharacterPicture mask for value formatting
lViewValLogicalShow data values on chart
lLegendsLogicalShow series legends
nBarSepNumericBar separation gap
nPointNumericPoint marker type (POINT_TYPE_1..3)
nMaxValNumericMaximum Y-axis value
nMinValNumericMinimum Y-axis value
nClrBackNumericBackground color
cBitmapCharacterBackground bitmap file

Methods

MethodDescription
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

See Also