GUICtrlCreateDiagramm by Faweyr

  • Dieses Script ermöglicht, ein Diagramm in das GUI einzubauen. Bis jetzt kann man 10 Balken erstellen. Ein weiteres updade des Sciptes wird mehr Balken ermöglichen. Was noch fehlt ist ein "GUICtrlSetDiagramm", also ein updade, mit dem man die Farbe und die % des Balkens verändern lässt.
    Ich freue mich über brauchbare Kritik.

    Spoiler anzeigen
    [autoit]

    GUICtrlCreateDiagramm (30, 30 , 300 , 200 ,-1,10,"",20,0xFF9933,30,0x33FF00,50,0x0066CC,20,0x00ff00,60,0x00ff00,70,0x00ff00,80,0x00ff00,"","","","")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func GUICtrlCreateDiagramm ($left, $top , $width , $height , $color , $d1, $c1, $d2, $c2, $d3, $c3, $d4, $c4, $d5, $c5, $d6, $c6, $d7, $c7, $d8, $c8, $d9, $c9, $d10, $c10)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Diagramm-Fenster erstellen:

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic($left, $top, $width+50,$height)

    [/autoit] [autoit][/autoit] [autoit]

    If not $color = "-1" then GUICtrlSetBkColor(-1, $color)

    [/autoit] [autoit][/autoit] [autoit]

    ;Anzahl der Balken zählen:
    Local $anzahl = 0
    If not $d1 = "" then $anzahl = $anzahl + 1
    If not $d2 = "" then $anzahl = $anzahl + 1
    If not $d3 = "" then $anzahl = $anzahl + 1
    If not $d4 = "" then $anzahl = $anzahl + 1
    If not $d5 = "" then $anzahl = $anzahl + 1
    If not $d6 = "" then $anzahl = $anzahl + 1
    If not $d7 = "" then $anzahl = $anzahl + 1
    If not $d8 = "" then $anzahl = $anzahl + 1
    If not $d9 = "" then $anzahl = $anzahl + 1
    If not $d10 = "" then $anzahl = $anzahl + 1

    [/autoit] [autoit][/autoit] [autoit]

    ;Höhe der Balken berechnen:
    Local $BalkenHoehe = (($height-20) / $anzahl)-3

    [/autoit] [autoit][/autoit] [autoit]

    ;1 Prozent des Balken berechnen:
    Local $Prozent = ($width-20) /100

    [/autoit] [autoit][/autoit] [autoit]

    ;Erstellen der Balken:
    If not $d1 = "" then
    Local $balken1 = GUICtrlCreateGraphic($left+10, $top +10 +3, $Prozent*$d1 , $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c1)
    $balken1 = GUICtrlCreateLabel ($d1 & "%", $width+50 ,$top +10 +4)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c1)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d2 = "" then
    Local $balken2 = GUICtrlCreateGraphic($left+10, $top+ 10 + $BalkenHoehe +6, $Prozent*$d2, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c2)
    $balken2 = GUICtrlCreateLabel ($d2 & "%", $width+50 ,$top +10 +7+ $BalkenHoehe)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c2)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d3 = "" then
    Local $balken3 = GUICtrlCreateGraphic($left+10,$top+ 10 +9+ $BalkenHoehe*2 , $Prozent*$d3, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c3)
    $balken3 = GUICtrlCreateLabel ($d3 & "%", $width+50 ,$top +10 +10+ $BalkenHoehe*2)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c3)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d4 = "" then
    Local $balken4 = GUICtrlCreateGraphic($left+10, $top+ 10 + 12+$BalkenHoehe*3 , $Prozent*$d4, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c4)
    $balken4 = GUICtrlCreateLabel ($d4 & "%", $width+50 ,$top +10 +13+ $BalkenHoehe*3)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c4)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d5 = "" then
    Local $balken5 = GUICtrlCreateGraphic($left+10, $top+ 10 +15+ $BalkenHoehe*4, $Prozent*$d5, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c5)
    $balken5 = GUICtrlCreateLabel ($d5 & "%", $width+50 ,$top +10 +16+ $BalkenHoehe*4)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c5)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d6 = "" then
    Local $balken6 = GUICtrlCreateGraphic($left+10, $top+ 10 +18+ $BalkenHoehe*5, $Prozent*$d6, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c6)
    $balken6 = GUICtrlCreateLabel ($d6 & "%", $width+50 ,$top +10 +19+ $BalkenHoehe*5)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c6)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d7 = "" then
    Local $balken7 = GUICtrlCreateGraphic($left+10, $top+ 10 +21+ $BalkenHoehe*6, $Prozent*$d7, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c7)
    $balken7 = GUICtrlCreateLabel ($d7 & "%", $width+50 ,$top +10 +22+ $BalkenHoehe*6)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c7)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d8 = "" then
    Local $balken8 = GUICtrlCreateGraphic($left+10, $top+ 10 + 24+$BalkenHoehe*7, $Prozent*$d8, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c8)
    $balken8 = GUICtrlCreateLabel ($d8 & "%", $width+50 ,$top +10 +25+ $BalkenHoehe*7)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c8)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d9 = "" then
    Local $balken9 = GUICtrlCreateGraphic($left+10,$top+ 10 + 27+$BalkenHoehe*8, $Prozent*$d9, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c9)
    $balken9 = GUICtrlCreateLabel ($d9 & "%", $width+50 ,$top +10 +28+ $BalkenHoehe*8)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c9)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    If not $d10 = "" then
    Local $balken10 = GUICtrlCreateGraphic($left+10, $top+ 10 +30+ $BalkenHoehe*9, $Prozent*$d10, $BalkenHoehe)
    GUICtrlSetBkColor(-1, $c10)
    $balken10 = GUICtrlCreateLabel ($d10 & "%", $width+50 ,$top +10 +31+ $BalkenHoehe*9)
    If not $color = "" then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor ( -1,$c10)
    endif

    [/autoit] [autoit][/autoit] [autoit]

    endfunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Einmal editiert, zuletzt von Faweyr (2. September 2009 um 14:52)

  • Hurra...entlich jemand, der was sagt...nach dem 2 script dachte ich fast schon, das ich nur Mist poste...
    jooaa..gute idee, danke

  • Nicht schlecht! :thumbup:
    Aber wie Nuts bereits gesagt hat ist es noch ziemlich lang. ;)

    Schnell gekürzte Fassung
    [autoit]

    GUICreate("Diagramm")
    GUICtrlCreateDiagramm(30, 30, 300, 200, -1, 10, "", 20, 0xFF9933, 30, 0x33FF00, 50, 0xabc, 100, 0x50aa50)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func GUICtrlCreateDiagramm($left, $top, $width, $height, $color, $d1, $c1, $d2 = "", $c2 = "", $d3 = "", $c3 = "", $d4 = "", $c4 = "", $d5 = "", $c5 = "", _
    $d6 = "", $c6 = "", $d7 = "", $c7 = "", $d8 = "", $c8 = "", $d9 = "", $c9 = "", $d10 = "", $c10 = "")

    [/autoit] [autoit][/autoit] [autoit]

    If Not $color = "-1" Then GUICtrlSetBkColor(-1, $color)
    Local $anzahl = Ceiling((@NumParams -5) / 2)

    [/autoit] [autoit][/autoit] [autoit]

    ;Höhe der Balken berechnen:
    Local $BalkenHoehe = (($height - 20) / $anzahl) - 3

    [/autoit] [autoit][/autoit] [autoit]

    ;1 Prozent des Balken berechnen:
    Local $Prozent = ($width - 20) / 100
    ;Erstellen der Balken:

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $anzahl
    Assign('balken'&$i, GUICtrlCreateGraphic($left + 10, $top + 10 + $BalkenHoehe *($i-1), $Prozent * Execute('$d'&$i), $BalkenHoehe))
    GUICtrlSetBkColor(-1, Execute('$c'&$i))
    $balken2 = GUICtrlCreateLabel(Execute('$d'&$i) & "%", $width + 50, $top + 10 + 7 + $BalkenHoehe*($i-1))
    If Not $color = "" Then GUICtrlSetBkColor(-1, $color)
    GUICtrlSetColor(-1, Execute('$c'&$i))
    Next
    EndFunc ;==>GUICtrlCreateDiagramm

    [/autoit]

    Da kann man aber auch noch einiges verbessern.

  • Danke für euer bemühen,
    ich werde mal schauen was zu machen ist, wobei ja jetzt schon ein script mit mehreren und besseren Diagrammen gibt.