This code uses a powerful GraphPlus library and a simple ChartView class.
/*
* MINIGUI - Harbour Win32 GUI library Demo
*/
#include "
hmg.ch"
#include "GraphPlus.ch"
#include "
hbclass.ch"
STATIC aTypes[ 4 ]
/*
* Description: Initializes the main window for a chart demo application.
* Parameters: None
* Return: NIL - No value returned.
* Purpose: Sets up a GUI with a grid for data input, chart type selection, and size controls to demonstrate GraphPlus charting; e.g., allows users to visualize data in various chart formats.
* Notes: Uses sample data for demonstration; window is fixed-size and centered.
*/
FUNCTION Main()
LOCAL aRows[ 6 ], aCombo := {}
aRows[ 1 ] := { 'Simpson', 5 }
aRows[ 2 ] := { 'Mulder', 30 }
aRows[ 3 ] := { 'Smart', 50 }
aRows[ 4 ] := { 'Grillo', 120 }
aRows[ 5 ] := { 'Kirk', 90 }
aRows[ 6 ] := { 'Barriga', 200 }
aTypes[ 1 ] := { "Pie", "PieChart" }
aTypes[ 2 ] := { "Line", "LineChart" }
aTypes[ 3 ] := { "Bar", "BarChart" }
aTypes[ 4 ] := { "Columns", "ColumnChart" }
AEval( aTypes, {| x | AAdd( aCombo, x[ 1 ] ) } )
DEFINE WINDOW Win_1 WIDTH 600 HEIGHT 500 TITLE "GraphPlus Chart Sample" MAIN
@ 20, 20 GRID Grid_1 ;
WIDTH 300 HEIGHT 110 ;
HEADERS { 'Label', 'Data' } ;
WIDTHS { 100, 100 } ;
ITEMS aRows ;
VALUE { 1, 1 } ;
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER' }, { 'TEXTBOX', 'NUMERIC', '9999' } } ;
EDIT ;
CELLNAVIGATION
@ 20, 390 COMBOBOX Combo_1 ;
WIDTH 135 HEIGHT 194 ;
ITEMS aCombo ;
VALUE 1 ;
ON LISTCLOSE This.Button_1.SetFocus()
@ 60, 390 TEXTBOX t_Width ;
WIDTH 50 ;
VALUE 480 ;
NUMERIC INPUTMASK "999"
@ 100, 390 TEXTBOX t_Height ;
WIDTH 50 ;
VALUE 250 ;
NUMERIC INPUTMASK "999"
@ 20, 340 LABEL Label_1 WIDTH 50 HEIGHT 20 VALUE 'Type'
@ 60, 340 LABEL Label_2 WIDTH 50 HEIGHT 20 VALUE 'Width'
@ 100, 340 LABEL Label_3 WIDTH 50 HEIGHT 20 VALUE 'Height'
@ 100, 460 BUTTON Button_1 ;
CAPTION "Generate" ;
ACTION GenerateChart() ;
WIDTH 70 HEIGHT 28 DEFAULT
END WINDOW
CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
RETURN NIL
/*
* Description: Generates a chart based on user input.
* Parameters: None
* Return: NIL - No value returned.
* Purpose: Creates and displays a chart using data from the grid, with type and size set by user controls; e.g., visualizes user-entered data in selected chart format.
* Notes: Adjusts chart properties based on type; pie charts show legends, others hide them for clarity.
*/
FUNCTION GenerateChart()
LOCAL aRows := Win_1.Grid_1.GetArray()
LOCAL data1 := {}
LOCAL data2 := {}
LOCAL oChartView
AEval( aRows, {| x | AAdd( data1, x[ 1 ] ) } )
AEval( aRows, {| x | AAdd( data2, x[ 2 ] ) } )
oChartView := ChartView():New( "Win_1", 150, 20, Win_1.t_Width.VALUE +70, Win_1.t_Height.VALUE +50 )
WITH OBJECT oChartView
:oGraph:LegendFont := array FONT 'Arial' SIZE 10
:SetData( data2, data1, data1 )
SWITCH Win_1.Combo_1.VALUE
CASE 1
:SetGraphType( GT_PIE )
:oGraph:LegendPos := LEGEND_ON_RIGHT
EXIT
CASE 2
:SetGraphType( GT_LINE )
:oGraph:lShowLegends := .F.
EXIT
CASE 3
:oGraph:BarGapRatio := 0
:oGraph:BarGapWidthRatio := 0.1
:SetGraphType( GT_BAR )
:oGraph:lShowLegends := .F.
EXIT
CASE 4
:SetGraphType( GT_COLUMNS )
:oGraph:lShowLegends := .F.
EXIT
END
:SetTitles( aTypes[ Win_1.Combo_1.Value ][ 1 ] + " Chart Sample" )
:Draw()
END WITH
RETURN NIL
Hope this is helpful.