Voici un script contenant la fonction _graph_camembert_update permettant d'afficher un camembert facilement à partir d'un tableau à dimension unique:
► Afficher le texte
Code : Tout sélectionner
#include <Array.au3>
#include <GUIConstantsEx.au3>
$gui1 = GUICreate("test de la fonction _graph_camembert_update", 586, 700, -1, -1, 0x00040000, 0x2000000)
GUISetBkColor(0xCDFEF8)
GUISetState()
global $data0[600]
$data0[0]=230
$data0[1]=100
$data0[2]=100
$data0[3]=12
$data0[4]=230
$data0[5]=100
$data0[6]=249
for $i = 0 to (UBound($data0)-1)/2
if $data0[$i] = "" then $data0[$i] = "texte"
Next
global $data1[20]
$data1[0]=230
$data1[1]=100
$data1[2]=100
$data1[3]=12
$data1[4]=230
$data1[5]=100
$data1[6]=249
$data1[7]="pomme"
$data1[8]=100
$data1[9]="pomme"
$data1[10]=251
$data1[11]=252
$data1[12]="pomme"
$data1[13]="tomate"
$data1[14]="pomme"
$data1[15]=256
$data1[16]="tomate"
$data1[17]=258
$data1[19]="tomate"
$data1[18]=259
global $data2[7]
$data2[0]=230
$data2[1]=100
$data2[2]=100
$data2[3]=12
$data2[4]=230
$data2[5]=100
$data2[6]=249
global $graph1
global $graph2
global $graph3
$graph1 = _graph_camembert_update($graph1,$data0,$gui1,10,25,"titre",200,200)
$graph2 = _graph_camembert_update($graph2,$data1,$gui1,40,280,"camembert 2",150,100,0xFE0E0E)
$graph3 = _graph_camembert_update($graph3,$data2,$gui1,40,450,"test",180,180,0xB2B2B2,0xB2B2B2,0xD5D5D5,0xB2B2B2,0xB2B2B2,0x0011FE)
$timer = TimerInit()
Do
if TimerDiff($timer) > 1000 then _modif_graph2()
Until GUIGetMsg() = -3;gui_event_close
func _modif_graph2()
redim $data1[Random(20,24,1)]
for $i = 0 to UBound($data1)-1
$data1[$i] = Random(1,8,1)
Next
$graph2 = _graph_camembert_update($graph2,$data1,$gui1,40,280,"camembert 2",150,100,0xFE0E0E)
$timer = TimerInit()
EndFunc
func _graph_camembert_update($graph,$data,$gui,$ileft=0,$itop=16,$titre="titre",$iwidth=180,$iheight=180,$cadre_color=0xFFFFFF,$bk_color=$GUI_BKCOLOR_TRANSPARENT,$bk_color_titre1=$GUI_BKCOLOR_TRANSPARENT,$bk_color_titre2=$GUI_BKCOLOR_TRANSPARENT,$bk_color_data=$GUI_BKCOLOR_TRANSPARENT,$cadre_color_pie="auto",$nb_limite_diff=0)
if $graph <> "" then
if $graph[16] <> "" Then ;delete labels precedents
for $i = $graph[16] to $graph[16]+$graph[17]+2
GUICtrlDelete($i)
Next
EndIf
_Graph_Delete($graph)
EndIf
$decalage_droit =1
$decalage_data_hauteur = 0
$hWnd = GUICtrlCreateGraphic($ileft,$itop,$iwidth+1,$iheight+1) ;creation du graphic
GUICtrlSetColor(-1,$cadre_color)
GUICtrlSetBkColor(-1,$bk_color)
Local $ahTicksLabelsX[1]
Local $ahTicksLabelsY[1]
Local $ahTicksX[1]
Local $ahTicksY[1]
Dim $graph[18] = ["",$hWnd,$ileft,$itop,$iwidth,$iheight,0,1,0,1, _
$ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY,$cadre_color,$bk_color]
if $nb_limite_diff = 0 then $nb_limite_diff=$graph[5]/16 -1
local $tmp_data_trie_nb1=""
$graph[16] = GUICtrlCreateLabel($titre,$graph[2],$graph[3]-16,$graph[4]+16+$decalage_droit,16)
GUICtrlSetBkColor(-1,$bk_color_titre1)
$tmp_txt = " % |nombre|valeur"
GUICtrlCreateLabel($tmp_txt,$graph[2]+$graph[4]+$decalage_droit+16,$graph[3]-16,StringLen($tmp_txt)*7,15)
GUICtrlSetFont(-1,8.5,400,-1,"Lucida console")
GUICtrlSetBkColor(-1,$bk_color_titre2)
GUICtrlCreateLabel("",$graph[2]+$graph[4]+$decalage_droit+16,$graph[3]-16+15,StringLen($tmp_txt)*7,1)
GUICtrlSetBkColor(-1,0x000000)
_calcul_camembert_data($data,$tmp_data_trie_nb1,$nb_limite_diff)
;_ArrayDisplay($tmp_data_trie_nb1)
$total_nb = UBound($data)
$start_angle = 90
$taille_dgr=0
$label_top = $graph[3]
$graph[17]=0
$taille_pourcent=""
for $i = 0 to ubound($tmp_data_trie_nb1)-1
$tmp_color = Random(0, 0xFFFFFF, 1)
if $cadre_color_pie = "auto" then
GUICtrlSetGraphic($graph[1],$GUI_GR_COLOR,$tmp_color,$tmp_color)
else
GUICtrlSetGraphic($graph[1],$GUI_GR_COLOR,$cadre_color_pie,$tmp_color)
EndIf
$taille_pourcent = ($tmp_data_trie_nb1[$i][1]/$total_nb)*100
$taille_dgr=($taille_pourcent*360)/100
$radius = $graph[4]/2
if $graph[5]/2 < $radius then $radius = $graph[5]/2
GUICtrlSetGraphic($graph[1], $GUI_GR_PIE, $graph[4]/2,$graph[5]/2,$radius,$start_angle, -$taille_dgr)
$start_angle -= $taille_dgr
GUICtrlCreateLabel("",$graph[2]+$graph[4]+$decalage_droit,$label_top,16,16)
GUICtrlSetBkColor(-1,$tmp_color)
$taille_pourcent = StringRight(" "&stringleft($taille_pourcent,5),5)&"%"
$nombre = stringright(" "&$tmp_data_trie_nb1[$i][1],5)
$tmp = GUICtrlCreateLabel($taille_pourcent&" | "&$nombre&"|"&$tmp_data_trie_nb1[$i][0],$graph[2]+$graph[4]+16+$decalage_droit,$label_top+$decalage_data_hauteur,-1,16)
GUICtrlSetFont($tmp,8.5,400,-1,"Lucida console")
GUICtrlSetBkColor(-1,$bk_color_data)
$tmp_2 = ControlGetPos($gui,"",$tmp)
GUICtrlSetPos($tmp,$tmp_2[0],$tmp_2[1],StringLen(GUICtrlRead($tmp))*7)
$graph[17] +=2
$label_top+=16
Next
GUISetState(@SW_UNLOCK,$gui)
GUISetState(@SW_SHOW,$gui)
return $graph
EndFunc
func _calcul_camembert_data($data,ByRef $tmp_data_trie_nb1,$nb_limite_diff)
dim $tmp_data_trie_nb1[ubound($data)][2]
dim $tmp_data_trie_nb2[ubound($data)][2]
_ArraySort($data)
for $i = 0 to UBound($data)-1
if $data[$i] = "" then $data[$i] = "[-vide-]"
Next
$tmp_data_nb=-1
$tmp_dico=""
$sort=0
for $i = 0 to UBound($data)-1
if not StringInStr($data[$i],$tmp_dico) Then
$tmp_data_nb+=1
$tmp_dico=$data[$i]
$tmp_data_trie_nb2[$tmp_data_nb][0]=$data[$i]
$tmp_data_trie_nb2[$tmp_data_nb][1]=1
Else
$tmp_data_trie_nb2[$tmp_data_nb][1]+=1
EndIf
Next
ReDim $tmp_data_trie_nb2[$tmp_data_nb+1][2]
_ArraySort($tmp_data_trie_nb2,1,0,0,1)
$tmp_data_nb=-1
$tmp_dico=""
$first_autre_data=0
for $i = 0 to ubound($tmp_data_trie_nb2)-1
if $nb_limite_diff-1 > $tmp_data_nb then
$tmp_data_nb+=1
$tmp_dico=$tmp_data_trie_nb2[$i][0]
$tmp_data_trie_nb1[$tmp_data_nb][0]=$tmp_data_trie_nb2[$i][0]
$tmp_data_trie_nb1[$tmp_data_nb][1]=$tmp_data_trie_nb2[$i][1]
Else
if $first_autre_data=0 then $tmp_data_trie_nb1[$tmp_data_nb][0]= "Reste: " & $tmp_data_trie_nb1[$tmp_data_nb][0]
$first_autre_data=1
if not StringInStr($tmp_dico,$data[$i]) then $tmp_data_trie_nb1[$tmp_data_nb][0]&=","&$tmp_data_trie_nb2[$i][0]
$tmp_dico&="|--|"&$tmp_data_trie_nb2[$i][0]
$tmp_data_trie_nb1[$tmp_data_nb][1]+=$tmp_data_trie_nb2[$i][1]
EndIf
Next
ReDim $tmp_data_trie_nb1[$tmp_data_nb+1][2]
EndFunc
Func _Graph_Delete(ByRef $aGraphArray)
;----- delete x ticks/labels -----
$ahTicksX = $aGraphArray[10]
$ahTicksLabelsX = $aGraphArray[11]
For $i = 1 to (UBound($ahTicksX) - 1)
GUICtrlDelete($ahTicksX[$i])
Next
For $i = 1 to (UBound($ahTicksLabelsX) - 1)
GUICtrlDelete($ahTicksLabelsX[$i])
Next
;----- delete y ticks/labels -----
$ahTicksY = $aGraphArray[12]
$ahTicksLabelsY = $aGraphArray[13]
For $i = 1 to (UBound($ahTicksY) - 1)
GUICtrlDelete($ahTicksY[$i])
Next
For $i = 1 to (UBound($ahTicksLabelsY) - 1)
GUICtrlDelete($ahTicksLabelsY[$i])
Next
Dim $ahTicksLabelsY[1]
;----- delete graphic control -----
GUICtrlDelete($aGraphArray[1])
;----- close array -----
$aGraphArray = 0
EndFunc