Jump to content
Sign in to follow this  

Bar Graph

Recommended Posts


A recent thread came up asking for a bar graph. I figured it would be kinda cool to have a udf to make bar graphs from an array of data.

Its kind of difficult to make it fully customizable, but here is a basic concept that someone could expand upon if they want muttley

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Dim $Array[12][3]
$Months = StringSplit("January,Febuary,March,April,May,June,July,August,Setpember,October,November,December",",")
Dim $Colors[3] = [0xFF0000,0x00FF00,0x0000FF]
For $i = 0 to UBound($Months)-1
$Array[$i][0] = $Months[$i]
$Array[$i][1] = $Colors[Random(0, 3)]
$Array[$i][2] = Random(100,300,1)
GUICreate("TEST", 800,400)
GuiCtrlCreateBarGraph($Array, 0,0)
While 1

Func GuiCtrlCreateBarGraph($Information, $Left, $Top, $Width=800, $Height=400, $Scale=1)
    $AxisColor = 0x000000
    ; $Array[x][0] = Column Name
    ; $Array[x][1] = Column Color
    ; $Array[x][2] = Value1
    If Not IsArray($Information) Or Not UBound($Information,0) = 2 or not UBound($Information,2) >= 3 then Return SetError(1 , "", -1)
    $Graphic = GUICtrlCreateGraphic($Left,$Top, $Width, $Height)
    $ItemBound = UBound($Information)
    $OffSet = 17
    GUICtrlSetGraphic($Graphic, $GUI_GR_PENSIZE, 2)
    GUICtrlSetGraphic($Graphic, $GUI_GR_COLOR, $AxisColor)
    GUICtrlSetGraphic($Graphic, $GUI_GR_MOVE, $Left+$Offset, $Top + $Height - $Offset)
    GUICtrlSetGraphic($Graphic, $GUI_GR_LINE, $Left + $Width, $Top + $Height -$Offset)
    GUICtrlSetGraphic($Graphic, $GUI_GR_MOVE, $Left+$Offset, $Top)
    GUICtrlSetGraphic($Graphic, $GUI_GR_LINE, $Left + $Offset, $Top + $Height -$Offset)
    $Spacing = $Width / $ItemBound +1
    $ColWidth = $Spacing / 2
    $BaseLabel_TPos = $Top+$Height-($OffSet-5)
    For $x = 1 to $ItemBound-1
        $LeftPos = $Spacing*($X) - $Offset
        $TopPos = ($Top + $Height)-$Offset - ($Information[$x][2] * $Scale)
        $ColHeight = $Top+$Height - $TopPos-$Offset
        GUICtrlSetGraphic($Graphic, $GUI_GR_COLOR, $Information[$x][1],$Information[$x][1])
        GUICtrlSetGraphic($Graphic, $GUI_GR_RECT, $LeftPos, $TopPos,$ColWidth,$ColHeight)
        $Label_LPos = $Spacing*($X) - $Offset
        $Label_TPos = $TopPos - 17
        GUICtrlCreateLabel($Information[$x][0], $Label_LPos, $BaseLabel_TPos,$Spacing,$OffSet-5)
        GUICtrlCreateLabel($Information[$x][2], $Label_LPos, $Label_TPos, $Spacing-5, 17)
Edited by Paulie

Share this post

Link to post
Share on other sites

Nice work!

To display graphics within an AutoIt GUI you may probably also have a look to imbed one of the (flash) graphic engines here. :D



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.