Comment faire un Graphe avec le composant gb.chart
Tout d'abord, activez le composant gb.chart dans votre projet.
Structure de données graphiques
La structure du composant chart est simple. Un gb.chart a :
- Un tableau de jeu de données (vous pouvez imaginer que c'est la rangée du jeu de données). Chaque jeu de données a un nom (en-tête de la rangée du tableau de données).
par défaut un premier jeu de données est créé.
- Une en-tête de tableau (en-tête de colonne de tableau). Cela définit le nombre de valeurs par séries que le graphique contient.
- Un jeu de données est un tableau qui contient des données en virgule flottante.
Exemples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| 'Initialise l'en-tête des colonnes
Chart.Headers = ["Tic", "Tac", "Toes"]
'Je n'ai qu'unjeu de données, pas besoin d'en ajouter un. 'Assigne les valeurs :
Chart[0].Values [1.0, 2.0, 3.0] ' Le .0 force a renvoyer un tableau float[]
'mais vous pouvez employer cette manière également : Chart[0].Add(1.0)
'Taille automatique des fontes, proportionnelle. 'Taille de fonte normale pour un graphique des 2/3 de la taille d'écran. Chart.Proportionnal = TRUE
'Définit le titre Chart.Title = "My Chart"
'Rend la legende visible Chart.Legend.Visible = TRUE Chart.Legend.Title = "My Legend"
Chart.YAxe.ShowIntervalLines.Visible = TRUE
'Type de graphique Chart.Type = ChartType.Lines
'Couleurs utilisateur Chart.Style = ChartStyle.Custom Chart.Colors.Values = [Color.yellow, Color.red, Color.Blue]
|
Enfin, tracé du graphique. Par exemple dans un tableau drawing :
1
2
3
4
5
6
7
| PUBLIC SUBDrawingArea1_Draw()
Chart.Width = DrawingArea1.ClientHeight Chart.Height = DrawingArea1.ClientWidth Chart.Draw()
END
|
Un autre exemple, ici de la logithèque de Gambas :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| ' Gambas class file
'Uploaded to the Gambas Farm 17/05/2017 '18/05/2017 Added Chart Types and resizable Chart 'Bugs or comments to bugs@cogier.com 'Code altered from this site 'https://novatocodegambas.blogspot.com/2015/09/ejemplo-de-componente-gbchart-graficas.html' 'Updated for QT5 08/12/22
bSkip AS BOOLEAN 'To skip the AllSliders routine while setting up the values bPlusMinus AS BOOLEAN
PUBLIC SUB Form_Open()
Chart.CountDataSets = 2 'How many data sets do you require = 2 Chart.Headers.Values = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] 'Header values Chart.Title.Text = "Percent" 'Chart heading Chart[0].Values = [20, 50, 10, 60, 30] 'Chart initial values Chart[1].Values = [15, 85, 25, 35, 55] 'Chart initial values 'Chart.Legend.Visible = True 'Makes the Legend visible Chart.Legend.Title = "Days" 'Title of chart Chart.Type = ChartType.Lines 'Type of chart Chart.BackGround = Color.Yellow 'Sets the background colour SliderBackGround.value = 16776960 LabelColour.text = Str(16776960) Chart.Border = FALSE 'Gets rid of the border DrawingArea1.Refresh 'Refresh the Drawing area
Slider1.value = Chart[0].Values[0] 'Slider value matches Chart[0].Values Slider2.value = Chart[0].Values[1] 'Slider value matches Chart[0].Values Slider3.value = Chart[0].Values[2] 'Slider value matches Chart[0].Values Slider4.value = Chart[0].Values[3] 'Slider value matches Chart[0].Values Slider5.value = Chart[0].Values[4] 'Slider value matches Chart[0].Values Slider6.value = Chart[1].Values[0] 'Slider value matches Chart[0].Values Slider7.value = Chart[1].Values[1] 'Slider value matches Chart[0].Values Slider8.value = Chart[1].Values[2] 'Slider value matches Chart[0].Values Slider9.value = Chart[1].Values[3] 'Slider value matches Chart[0].Values Slider10.value = Chart[1].Values[4] 'Slider value matches Chart[0].Values bSkip = TRUE 'Now the AllSliders routing can go to work AllSliders_Change 'Run the AllSliders_Change routine
END
|
1
2
3
4
5
6
7
8
9
10
11
| PUBLIC SUB AllRadio_Click() 'When a RadiButton is clicked
DIM oObj AS OBJECT 'Object needed
FOR EACH oObj IN HBoxType.Children 'For each of the Children (RadioButtons in this case) in the HBoxType IF oObj.Value = TRUE THEN Chart.Type = Val(oObj.tag) 'If the Value is true (it's been clicked) then set the chart type to the value of the RadioButton's Tag NEXT
DrawingArea1.Refresh 'Refresh the DrawingArea
END
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| PUBLIC SUB DrawingArea1_Draw() 'Required to draw the chart
DIM siHeight, siWidth AS SHORT 'For Height and Width of the Chart
siHeight = DrawingArea1.Height - 10 'Set the value to 10 less than the DrawingArea Height siWidth = DrawingArea1.Width - 10 'Set the value to 10 less than the DrawingArea Width IF siHeight < 10 THEN siHeight = 10 'Make sure the value is not too small IF siWidth < 10 THEN siWidth = 10 'Make sure the value is not too small
Chart.Height = siHeight 'Set the Chart Height Chart.Width = siWidth 'Set the Chart Width Chart.Draw 'Draw the chart
END
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| PUBLIC SUB AllSliders_Change() 'If a slider is moved..
IF NOT bSkip THEN RETURN 'Get out of here during inital setup Chart[0].Values = [Slider1.Value, Slider2.Value, Slider3.Value, Slider4.Value, Slider5.Value] 'Set the chart values up based on the slider values Chart[1].values = [Slider6.Value, Slider7.Value, Slider8.Value, Slider9.Value, Slider10.Value] 'Set the chart values up based on the slider values DrawingArea1.Refresh 'Redraw the chart
ValueBox1.value = Slider1.Value 'Set the ValueBox to show slide value ValueBox2.value = Slider2.Value 'Set the ValueBox to show slide value ValueBox3.value = Slider3.Value 'Set the ValueBox to show slide value ValueBox4.value = Slider4.Value 'Set the ValueBox to show slide value ValueBox5.value = Slider5.Value 'Set the ValueBox to show slide value ValueBox6.value = Slider6.Value 'Set the ValueBox to show slide value ValueBox7.value = Slider7.Value 'Set the ValueBox to show slide value ValueBox8.value = Slider8.Value 'Set the ValueBox to show slide value ValueBox9.value = Slider9.Value 'Set the ValueBox to show slide value ValueBox10.value = Slider10.Value 'Set the ValueBox to show slide value
END
|
1
2
3
4
5
6
7
| PUBLIC SUB SliderBackGround_Change() 'Background slider
Chart.BackGround = SliderBackGround.Value 'Set the Chart background colour to the value of the slider LabelColour.Text = Str(SliderBackGround.Value) 'Put the value in the Label DrawingArea1.Refresh 'Refresh the drawing
END
|
1
2
3
4
5
6
7
| PUBLIC SUB Overs_Enter() 'If the mouse Enters the 'Overs' panels then..
IF LAST.name = "PanelPlus" THEN bPlusMinus = TRUE 'If the mouse is over the 'Plus' panel then bPlusMinus = True IF LAST.name = "PanelMinus" THEN bPlusMinus = FALSE 'If the mouse is over the 'Minus' panel then bPlusMinus = False Timer1.Start 'Start the timer
END
|
1
2
3
4
5
| PUBLIC SUB Overs_Leave() 'If the mouse Leaves the 'Overs' panels then..
Timer1.Stop 'Stop the timer
END
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| PUBLIC SUB Timer1_Timer() 'Timer
DIM iSlider AS INTEGER = SliderBackGround.Value 'iSlider = the Sliders Value
IF NOT bPlusMinus THEN 'If bPlusMinus is False then.. DEC iSlider 'iSlider = iSlider - 1 IF iSlider < 0 THEN iSlider = 0 'Make sure iSlider stays above -1 Chart.BackGround = iSlider 'Set the Chart Background to iSlider ELSE 'Else (If bPlusMinus is True then..) INC iSlider 'iSlider = iSlider + 1 IF iSlider > 16777215 THEN iSlider = 16777215 'Make sure iSlider stays Below 16777216 Chart.BackGround = iSlider 'Set the Chart Background to iSlider END IF
LabelColour.Text = Str(iSlider) 'Add the colour Value to the Label SliderBackGround.value = iSlider 'Change the Slider Value DrawingArea1.Refresh 'Refresh the Chart
END
|
Une image, application de ce code :

====================
Navigation :
<-- Sommaire du WIKI : <-- <-- États de sortie <--====================
Documentation :
====================