Jump to content
Sign in to follow this  
taietel

3D Bar Graph

Recommended Posts

This is great, it helped me with a project i was working on.

The difference is i needed seperate colors per bar

Posted Image

please find the code for this if anyone needs it:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>


;customize colors
global $arColours[1]
$arColours = StringSplit("0xDD3333|0xDD7733|0xDDDD33|0x33DD33|0x3333DD|0x773377|0x777777|0x33DDDD|0x33DD77|0x77DD33|0x3377DD|0x7733DD|0xDD7777|0x77DD77|0x7777DD|0xDDDD77|0xDD77DD|0x77DDDD|0x773333|0x337733|0x333377|0x777733||0x337777|0xDD3377|0xDDDD33|0xDD33DD","|")

;customize data
local $GraphData[6][8]
$GraphData[0][0] = "Title - Subtitle" ;title
;column titles
$GraphData[1][0] = "Dan"
$GraphData[2][0] = "Bob"
$GraphData[3][0] = "Troy"
$GraphData[4][0] = "Luke"
$GraphData[5][0] = "Peter"
;Row titles
$graphData[0][1] = "Mon"
$graphData[0][2] = "Tue"
$graphData[0][3] = "Wed"
$graphData[0][4] = "Thu"
$graphData[0][5] = "Fri"
$graphData[0][6] = "Sat"
$graphData[0][7] = "Sun"

;make random data
for $ic = 1 to 5
    for $ir = 1 to 7
        $graphData[$ic][$ir] = random (5,10)
    Next
Next

Example($graphData)

Func Example($graphData)
    Local $gui = GUICreate($graphData[0][0], 450, 400)
    GUISetBkColor(0xffffff)

    _CreateBarChart($graphData,-1,-1,400,350)
    GUISetState()
    While 1
    Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                ;Example3()
                Exit
        EndSwitch
    WEnd
EndFunc


; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($graphData,$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $graphData - Array of graph data
;
;                   $iX - left margin, [Optional]
;                   $iY - top margin, [Optional]
;                   $iW - width of the graph, [Optional]
;                   $iH - height of the graph, [Optional]
;
; Return values..:  none
;
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; ...............:  modified by Daniel Barnes (djbarnes at orcon dot net dot en zed)
; ===============================================================================================================
Func _CreateBarChart($graphData,$iX=20,$iY=20,$iW=400,$iH=400)
    ;create title array - title[0] = main title, title[1] = sub title
    $title = StringSplit($graphData[0][0]," - ",1)
    local $columnNames[UBound($graphData,1)]
    local $columns = UBound($graphData,1)-1
    local $rowNames[UBound($graphData,2)]
    local $rows = UBound($graphData,2)-1
    local $runningtotal[$columns+1] ;column total height - in pixels
    local $runningtotalNum[$columns+1] ;column totals - in numbers

    ;set row and column names
    ;column
    for $i = 1 to $columns
        $columnNames[$i] = $graphData[$i][0]
        if $columnNames[$i] <> "" then $columnNames[0] = true ;yes, there are column names
    Next

    ;row
    for $i = 1 to $rows
        $rowNames[$i] = $graphData[0][$i]
        if $rowNames[$i] <> "" then $rowNames[0] = true ;yes, there are row names
    Next

    ;max is the height of the graph (the max value)
    Local $max=_largestValue($graphData);compare numerically

    ;set default values for the frame
    If $iX=-1 Then $iX=20
    If $iY=-1 Then $iY=20
    If $iW=-1 Then $iW=400
    If $iH=-1 Then $iH=400

    ;create frame for the chart
    $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)

    ;create title
    GUICtrlCreateLabel($title[1],$iX+15, $iY+10,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    if $title[0] > 1 then GUICtrlCreateLabel($title[2],$iX+15, $iY+25,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

    Local $Canvas
    If $rowNames[0] Then ;if there are row names then create a legend
        $Canvas = _CreateBarCanvas($iX+5, $iY, $iW-110, $iH-60) ;the canvas needs to be smaller, to fit the legend in!
        GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5)
        For $iRow=1 To $rows
            GUICtrlCreateGraphic($Canvas[0]+$Canvas[2]+19, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($rowNames))*$iRow-1,($iW-$Canvas[2])/2-30+1,15,0)
            $width=($iW-$Canvas[2])/2-30+2
            $height=15
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$iRow]-0x333333, $arColours[$iRow]-0x333333)
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, $width,$height)

            ;GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$iRow]-0x333333, $arColours[$iRow])
            GUICtrlCreateLabel($rowNames[$iRow],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($rowNames))*$iRow,($iW-$Canvas[2])/2-30,13,$SS_CENTER)
            GUICtrlSetColor(-1,_InvertColor(_InvertColor($arColours[$iRow])))
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$arColours[$iRow])
        Next
        GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else ;no legend
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60) ;normal canvas size
        For $i=1 To $columns
            GUICtrlCreateLabel($columnNames[$i],$iX+52+(($Canvas[2]/UBound($columnNames)))*$i+5, $iY+$iH-30)
            GUICtrlSetColor(-1,0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf

    ;draw the bars
    GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0)
    For $iColumn =1 To $columns
        for $iRow = 1 to $rows
            For $j=$Canvas[4]/2.5 To 0 Step -0.5
                GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$iRow]-0x333333, $arColours[$iRow])
                $left =5+($Canvas[2]/($columns))*($iColumn-1)+$j
                $width=0.5*($Canvas[2]/($columns))
                $top=-2+$Canvas[3]-$j+$runningtotal[$iColumn]
                $height =  -($Canvas[3]/_RoundUp($max))*($graphData[$iColumn][$iRow]) ;negative makes them go up, not down!
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $left, $top, $width,$height-1)
            Next
            $runningtotal[$iColumn] += $height
            $runningtotalNum[$iColumn] += $graphData[$iColumn][$iRow]
        next
    Next
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)

    ;values from the top of the bars
    For $iColumn = 1 to $columns
        $left =20+($Canvas[2]/($columns))*($iColumn)+($Canvas[4]/2.5)
        $top=-2+$Canvas[3]+$runningtotal[$iColumn]+50
        GUICtrlCreateLabel(Round($runningtotalNum[$iColumn]),$left+1,$top+1 ) ;shadow
        GUICtrlSetColor(-1,0)
        GUICtrlSetFont(-1, 8.5, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        GUICtrlCreateLabel(Round($runningtotalNum[$iColumn]),$left,$top )
        GUICtrlSetColor(-1,0xFFFFFF)
        GUICtrlSetFont(-1, 8.5, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next

    ;column labels - bottom of bars
    if $columnNames[0] then
        For $iColumn = 1 to $columns
            $left =5+($Canvas[2]/($columns))*($iColumn)+($Canvas[4]/2.5)
            $top=-2+$Canvas[3]+70
            GUICtrlCreateLabel($columnNames[$iColumn],$left+1,$top+1 ) ;shadow
            GUICtrlSetColor(-1,0)
            GUICtrlSetFont(-1, 7, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
            GUICtrlCreateLabel($columnNames[$iColumn],$left,$top )
            GUICtrlSetColor(-1,0xFFFFFF)
            GUICtrlSetFont(-1, 7, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    endif

    ;Y Axis
    For $i=0 To $Canvas[3] Step $Canvas[3]/5
        GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT)
        GUICtrlSetColor(-1,0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
EndFunc
#Region INTERNAL USE ONLY
Func _RoundUp($m)
    Local $rv = Round(Ceiling($m/10)*10,-1)
    ;ConsoleWrite($rv&@CRLF)
    Return $rv
EndFunc

Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=25, $BgColor=0xEEEEEE)
    Local $iXCanvas=$iX+$iDepthCanvas
    Local $iYCanvas=$iY+10+2*$iDepthCanvas
    Local $iWCanvas=$iW-2*$iDepthCanvas
    Local $iHCanvas=$iH-2*$iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
                Local $BgColor3 = $BgColor - 0x666666
    ;create bg for the bars
    For $i=0 To $iDepthCanvas; Step 0.5
        GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1)
    ;horizontal grid
    For $i=0 To $iHCanvas Step $iHCanvas/5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)

        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas)
    Next
    Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2)
    ;ConsoleWrite($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&@CRLF)
    Return $Canvas
EndFunc
#EndRegion INTERNAL USE ONLY

func _largestValue($array)
    $max = -99999
    $cols = UBound($array)-1
    $rows = UBound($array,2)-1
    for $ic = 1 to $cols
        $total = 0
        for $ir= 1 to $rows
            $total += $array[$ic][$ir]
        Next
        if $total > $max then $max = $total
    Next
    return $max
EndFunc


func _InvertColor($col)
    $col = String(Hex($col,6))
    $red = dec(StringMid($col,1,2))
    $green = dec(StringMid($col,3,2))
    $blue = dec(StringMid($col,5,2))
    $black = 0
    if $red < 0x88 Then
        $black -= 1
    Else
        $black += 1
    endif
    if $green < 0x88 Then
        $black -= 1
    Else
        $black +=1
    endif
    if $blue < 0x88 Then
        $black -= 1
    Else
        $black +=1
    endif

    if $black >= 0 Then
        ConsoleWrite($col &" -> 0x000000"&@CRLF)
        return 0x000000
    Else
        ConsoleWrite($col &" -> 0xFFFFFF"&@CRLF)
        return 0xFFFFFF
    endif

    $ret = "0x"&string(hex($red,2)&hex($green,2)&hex($blue,2))
    ConsoleWrite($ret&@CRLF)
    return $ret
EndFunc

Share this post


Link to post
Share on other sites

Hi I like the graph and I found it usefull to my needs but there is some issue that cause me some problems.

How to set the left/top position of the graph on the form?

I found that when changing the margin, the values on the top of the bars are set not above the bars.

How to fix it?

regards.

EDIT:

BTW: I made some little modification to the function so its will be suitable when resizing the form. All control IDs are set in array so you can call GUICtrlSetResizing function simmilar to this.

For $i =0 to UBound($aChartControls) -1

GUICtrlSetResizing ( $aChartControls[$i], $GUI_DOCKALL )

Next

but still I need the solution how to set the location of the grapth

EDIT2:

Just found the faulty code: The problem is when setting the height of this label:

GUICtrlCreateLabel($arValues[$i], $Canvas[0] + ($Canvas[2] / UBound($arValues)) * $i, $iH - $Canvas[1] + $Canvas[4] - 10 - (($Canvas[3] / _RoundUp($max)) * $arValues[$i]))

Global $aChartControls[10]

; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $sTitle1 - Title of the graph, [Optional]
;                   $sTitle2 - Subtitle of the graph, [Optional]
;                   $iX - left margin, [Optional]
;                   $iY - top margin, [Optional]
;                   $iW - width of the graph, [Optional]
;                   $iH - height of the graph, [Optional]
;
; Return values..:  none
;
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; Remarks........:  $array = ["name",value]
;                    - one with numbers/names (try to uncoment/coment them)
;                    - one with values
; ===============================================================================================================
Func _CreateBarChart(ByRef $arNames, ByRef $arValues, $sTitle1 = "", $sTitle2 = "", $iX = 20, $iY = 20, $iW = 400, $iH = 400)
    Local $max = _ArrayMax($arValues, 1);compare numerically
    ;Local $values = UBound($arValues)
    Local $arColours[UBound($arNames)]
    Local $color
    For $i = 0 To UBound($arValues) - 1
        $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1)
        $arColours[$i] = $color
    Next
    ;set default values for the frame
    If $iX = -1 Then $iX = 20
    If $iY = -1 Then $iY = 20
    If $iW = -1 Then $iW = 400
    If $iH = -1 Then $iH = 400
    ;create frame for the chart
    $aChartControls[0] = 0
    _RedimArrayControls()
            $aChartControls[$aChartControls[0]] = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)
    ;title
    _RedimArrayControls()
    $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel($sTitle1, $iX + 15, $iY + 10, $iW - 30, -1, $SS_CENTER)
    GUICtrlSetColor(-1, 0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _RedimArrayControls()
    $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel($sTitle2, $iX + 15, $iY + 25, $iW - 30, -1, $SS_CENTER)
    GUICtrlSetColor(-1, 0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    Local $Canvas
    If IsString($arNames[1]) Then
        $Canvas = _CreateBarCanvas($iX + 15, $iY + 15, $iW - 110, $iH - 60)
        _ArrayDisplay($Canvas)
        ;$aChartControls[0] += 1
        _RedimArrayControls()
        $aChartControls[$aChartControls[0]] = GUICtrlCreateGroup("Legend", $Canvas[0] + $Canvas[2] + 10, $Canvas[1] - 5, ($iW - $Canvas[2]) / 2 - 10, $Canvas[3] + $Canvas[4] + 5)
        For $i = 0 To UBound($arNames) - 1
            _RedimArrayControls()
            $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel($arNames[$i], $Canvas[0] + $Canvas[2] + 20, $Canvas[1] + 10 + (($Canvas[3] + $Canvas[4] - 15) / UBound($arNames)) * $i, ($iW - $Canvas[2]) / 2 - 30, 13, $SS_CENTER)
            ;$aChartControls[0] += 1
            GUICtrlSetColor(-1, $arColours[$i] - 0x444444)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1, $arColours[$i])
        Next
        _RedimArrayControls()
        $aChartControls[$aChartControls[0]] = GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else
        $Canvas = _CreateBarCanvas($iX + 15, $iY + 15, $iW - 50, $iH - 60)
        
        For $i = 0 To UBound($arNames) - 1
            _RedimArrayControls()
            $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel($arNames[$i], $iX + 52 + (($Canvas[2] / UBound($arNames))) * $i + 5, $iY + $iH - 30)
            GUICtrlSetColor(-1, 0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf
    ;draw the bars
    _RedimArrayControls()
    $aChartControls[$aChartControls[0]] = GUICtrlCreateGraphic($Canvas[0] - 0.5 * $Canvas[4], $Canvas[1] + 0.5 * $Canvas[4], $Canvas[2], $Canvas[3], 0)
    For $i = 0 To UBound($arValues) - 1
        For $j = $Canvas[4] / 2.5 To 0 Step -0.5
            _RedimArrayControls()
            $aChartControls[$aChartControls[0]] = GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i] - 0x333333, $arColours[$i])
            _RedimArrayControls()
            $aChartControls[$aChartControls[0]] = GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5 + ($Canvas[2] / UBound($arValues)) * $i + $j, -2 + $Canvas[3] - $j, 0.5 * ($Canvas[2] / UBound($arValues)), -($Canvas[3] / _RoundUp($max)) * $arValues[$i])
        Next
    Next
    _RedimArrayControls()
    $aChartControls[$aChartControls[0]] = GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
    For $i = 0 To UBound($arValues) - 1
        ;values from the top of the bars
        _RedimArrayControls()
        $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel($arValues[$i], $Canvas[0] + ($Canvas[2] / UBound($arValues)) * $i, $iH - $Canvas[1] + $Canvas[4] - 10 - (($Canvas[3] / _RoundUp($max)) * $arValues[$i]))
        GUICtrlSetColor(-1, 0x002244)
        GUICtrlSetFont(-1, 7, 800, 0, "Arial")
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    Next
    ;Y Axis
    For $i = 0 To $Canvas[3] Step $Canvas[3] / 5
        _RedimArrayControls()
        $aChartControls[$aChartControls[0]] = GUICtrlCreateLabel(($i / $Canvas[3]) * _RoundUp($max), $Canvas[0] - 65, $Canvas[1] + $Canvas[3] + $Canvas[4] - $i, 30, -1, $SS_RIGHT)
        GUICtrlSetColor(-1, 0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    Next
    _RedimArrayControls()
    $aChartControls[$aChartControls[0]] = GUICtrlCreateGroup("", -99, -99, 1, 1)

EndFunc   ;==>_CreateBarChart
#Region INTERNAL USE ONLY

Func _RedimArrayControls()
    $aChartControls[0] += 1
    If $aChartControls[0] > UBound($aChartControls) - 1 Then
        ReDim $aChartControls[$aChartControls[0] + 10]
    EndIf
    ;consolewrite(UBound() & $aChartControls[0] & @LF)
EndFunc   ;==>_RedimArrayControls

Func _RoundUp($m)
    Local $rv = Round(Ceiling($m / 10) * 10, -1)
    ;ConsoleWrite($rv&@CRLF)
    Return $rv
EndFunc   ;==>_RoundUp

Func _CreateBarCanvas($iX = 0, $iY = 0, $iW = 400, $iH = 400, $iDepthCanvas = 30, $BgColor = 0xEEEEEE)
    Local $iXCanvas = $iX + $iDepthCanvas
    Local $iYCanvas = $iY + 10 + 2 * $iDepthCanvas
    Local $iWCanvas = $iW - 2 * $iDepthCanvas
    Local $iHCanvas = $iH - 2 * $iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
    ;create bg for the bars
    For $i = 0 To $iDepthCanvas; Step 0.5
        _RedimArrayControls()
        $aChartControls[$aChartControls[0]] = GUICtrlCreateGraphic($iXCanvas + $i, $iYCanvas - $i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas - 1, $iHCanvas + $iDepthCanvas + 1)

    ;horizontal grid
    For $i = 0 To $iHCanvas Step $iHCanvas / 5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i + $iDepthCanvas)
    Next
    Local $Canvas = StringSplit($iXCanvas + $iDepthCanvas & "|" & $iYCanvas - $iDepthCanvas & "|" & $iWCanvas & "|" & $iHCanvas & "|" & $iDepthCanvas, "|", 2)
    ;ConsoleWrite($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&@CRLF)
    Return $Canvas
EndFunc   ;==>_CreateBarCanvas
#EndRegion INTERNAL USE ONLY
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Isakizada, try now:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Global $arNames[12]
Global $arValues[12]

Example1()

Func Example1()
    Local $gui = GUICreate("Example 1: 3D Bar Graph - left=20 (default) top=40", 850, 700)
    GUISetBkColor(0xffffff)
    $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2)
    For $i=0 To 11
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 1",-1,40,500,400)
    GUISetState()
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Example2()
        EndSwitch
    WEnd
EndFunc

Func Example2()
    Local $gui = GUICreate("Example 2: 3D Bar Graph - Chart at different position", 650, 550)
    GUISetBkColor(0xffffff)
    For $i=0 To 11
        $arNames[$i]=$i+1
    Next
    For $i=0 To 11
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 2",50,20,400,450)
    GUISetState()
    While 1
    Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Example3()
        EndSwitch
    WEnd
EndFunc

Func Example3()
    ReDim $arNames[16]
    ReDim $arValues[16]
    Local $gui = GUICreate("Example 3: 3D Bar Graph - Two charts at different positions", 950, 750)
    GUISetBkColor(0xffffff)
    For $i=0 To 15
        $arNames[$i]=$i+1
    Next
    For $i=0 To 15
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 3 - without legend",50,80,400,500)
    $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2)
    _CreateBarChart("3D Bar Chart","Example 3 - with legend",500,100,400,600)
    GUISetState()
    While 1
    Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                ;Example3()
                Exit
        EndSwitch
    WEnd
EndFunc


; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $sTitle1 - Title of the graph, [Optional]
;                   $sTitle2 - Subtitle of the graph, [Optional]
;                   $iX - left margin, [Optional]
;                   $iY - top margin, [Optional]
;                   $iW - width of the graph, [Optional]
;                   $iH - height of the graph, [Optional]
;
; Return values..:  none
; Version........:  2
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; ===============================================================================================================
Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
    Local $max=_ArrayMax($arValues,1);compare numerically
    ;Local $values = UBound($arValues)
    Local $arColours[UBound($arNames)]
    Local $color
    For $i=0 To UBound($arValues)-1
        $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1)
        $arColours[$i]=$color
    Next
    ;set default values for the frame
    If $iX=-1 Then $iX=20
    If $iY=-1 Then $iY=20
    If $iW=-1 Then $iW=400
    If $iH=-1 Then $iH=400
    ;create frame for the chart
    $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)
    ;title
    GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Local $Canvas
    If IsString($arNames[1]) Then
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60)
        GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER)
            GUICtrlSetColor(-1,$arColours[$i]-0x444444)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$arColours[$i])
        Next
        GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30)
            GUICtrlSetColor(-1,0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf
    ;draw the bars
    GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0)
    For $i=0 To UBound($arValues)-1
        For $j=$Canvas[4]/2.5 To 0 Step -0.5
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i])
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        Next
    Next
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)
    For $i=0 To UBound($arValues)-1
        ;values from the top of the bars
        GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        GUICtrlSetColor(-1,0x002244)
        GUICtrlSetFont(-1, 7, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    ;Y Axis
    For $i=0 To $Canvas[3] Step $Canvas[3]/5
        GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT)
        GUICtrlSetColor(-1,0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
EndFunc
#Region INTERNAL USE ONLY
Func _RoundUp($m)
    Local $rv = Round(Ceiling($m/10)*10,-1)
    Return $rv
EndFunc

Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE)
    Local $iXCanvas=$iX+$iDepthCanvas
    Local $iYCanvas=$iY+10+2*$iDepthCanvas
    Local $iWCanvas=$iW-2*$iDepthCanvas
    Local $iHCanvas=$iH-2*$iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
    ;create bg for the bars
    For $i=0 To $iDepthCanvas
        GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1)
    ;horizontal grid
    For $i=0 To $iHCanvas Step $iHCanvas/5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)

        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas)
    Next
    Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2)
    Return $Canvas
EndFunc
#EndRegion INTERNAL USE ONLY

Share this post


Link to post
Share on other sites

Very snazzy! I'm impressed with the simplistic beauty and professional look. I probably incorporate some of this into a regression suite I'm writing. If I do, I'll talk to you about permissions and credit. Thanks!


[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]

Share this post


Link to post
Share on other sites

Isakizada, try now:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Global $arNames[12]
Global $arValues[12]

Example1()

Func Example1()
    Local $gui = GUICreate("Example 1: 3D Bar Graph - left=20 (default) top=40", 850, 700)
    GUISetBkColor(0xffffff)
    $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2)
    For $i=0 To 11
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 1",-1,40,500,400)
    GUISetState()
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Example2()
        EndSwitch
    WEnd
EndFunc

Func Example2()
    Local $gui = GUICreate("Example 2: 3D Bar Graph - Chart at different position", 650, 550)
    GUISetBkColor(0xffffff)
    For $i=0 To 11
        $arNames[$i]=$i+1
    Next
    For $i=0 To 11
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 2",50,20,400,450)
    GUISetState()
    While 1
    Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                Example3()
        EndSwitch
    WEnd
EndFunc

Func Example3()
    ReDim $arNames[16]
    ReDim $arValues[16]
    Local $gui = GUICreate("Example 3: 3D Bar Graph - Two charts at different positions", 950, 750)
    GUISetBkColor(0xffffff)
    For $i=0 To 15
        $arNames[$i]=$i+1
    Next
    For $i=0 To 15
        $arValues[$i]=Random(0,200,1)
    Next
    _CreateBarChart("3D Bar Chart","Example 3 - without legend",50,80,400,500)
    $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2)
    _CreateBarChart("3D Bar Chart","Example 3 - with legend",500,100,400,600)
    GUISetState()
    While 1
    Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($gui)
                ;Example3()
                Exit
        EndSwitch
    WEnd
EndFunc


; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $sTitle1 - Title of the graph, [Optional]
;                   $sTitle2 - Subtitle of the graph, [Optional]
;                   $iX - left margin, [Optional]
;                   $iY - top margin, [Optional]
;                   $iW - width of the graph, [Optional]
;                   $iH - height of the graph, [Optional]
;
; Return values..:  none
; Version........:  2
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; ===============================================================================================================
Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
    Local $max=_ArrayMax($arValues,1);compare numerically
    ;Local $values = UBound($arValues)
    Local $arColours[UBound($arNames)]
    Local $color
    For $i=0 To UBound($arValues)-1
        $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1)
        $arColours[$i]=$color
    Next
    ;set default values for the frame
    If $iX=-1 Then $iX=20
    If $iY=-1 Then $iY=20
    If $iW=-1 Then $iW=400
    If $iH=-1 Then $iH=400
    ;create frame for the chart
    $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)
    ;title
    GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Local $Canvas
    If IsString($arNames[1]) Then
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60)
        GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER)
            GUICtrlSetColor(-1,$arColours[$i]-0x444444)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$arColours[$i])
        Next
        GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30)
            GUICtrlSetColor(-1,0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf
    ;draw the bars
    GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0)
    For $i=0 To UBound($arValues)-1
        For $j=$Canvas[4]/2.5 To 0 Step -0.5
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i])
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        Next
    Next
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)
    For $i=0 To UBound($arValues)-1
        ;values from the top of the bars
        GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        GUICtrlSetColor(-1,0x002244)
        GUICtrlSetFont(-1, 7, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    ;Y Axis
    For $i=0 To $Canvas[3] Step $Canvas[3]/5
        GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT)
        GUICtrlSetColor(-1,0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
EndFunc
#Region INTERNAL USE ONLY
Func _RoundUp($m)
    Local $rv = Round(Ceiling($m/10)*10,-1)
    Return $rv
EndFunc

Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE)
    Local $iXCanvas=$iX+$iDepthCanvas
    Local $iYCanvas=$iY+10+2*$iDepthCanvas
    Local $iWCanvas=$iW-2*$iDepthCanvas
    Local $iHCanvas=$iH-2*$iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
    ;create bg for the bars
    For $i=0 To $iDepthCanvas
        GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1)
    ;horizontal grid
    For $i=0 To $iHCanvas Step $iHCanvas/5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)

        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas)
    Next
    Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2)
    Return $Canvas
EndFunc
#EndRegion INTERNAL USE ONLY

Hi Taietel,

Thank you! its works as expected.

Thanks for sharing and supporting, I will use it in my project. :)


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

EDIT* I figured it out i put alot of GuiCtrlSetState(-1,$GUI_ONTOP) in the code.

Thanks

Hi

I love the bar graph. Im trying to make it work on top of a tabbed gui does anyone know how to do this?

thanks

Edited by engjcowi

Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

@engjcowi:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
 
Global $arNames[12]
Global $arValues[12]
GUICreate("3D Bar Graph on Tabs - Example", 610, 410)
GUICtrlCreateTab(5, 5, 600, 400)
$Tab1 = GUICtrlCreateTabItem("Tab1")
$arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2)
For $i=0 To 11
$arValues[$i]=Random(0,200,1)
Next
_CreateBarChart("3D Bar Chart","Example 1",-1,30,560,360)
 
$Tab2 = GUICtrlCreateTabItem("Tab2")
For $i=0 To 11
   $arNames[$i]=$i+1
Next
For $i=0 To 11
$arValues[$i]=Random(0,200,1)
Next
_CreateBarChart("3D Bar Chart","Example 2",50,50,400,300)
 
$Tab3 = GUICtrlCreateTabItem("Tab3")
ReDim $arNames[16]
ReDim $arValues[16]
For $i=0 To 15
   $arNames[$i]=$i+1
Next
For $i=0 To 15
$arValues[$i]=Random(0,200,1)
Next
$arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2)
_CreateBarChart("3D Bar Chart","Example 3 - with legend",30,30,560,360)
 
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
 
While 1
Sleep(10)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
 
EndSwitch
WEnd
 
; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $sTitle1 - Title of the graph, [Optional]
;                   $sTitle2 - Subtitle of the graph, [Optional]
;                   $iX - left margin, [Optional]
;                   $iY - top margin, [Optional]
;                   $iW - width of the graph, [Optional]
;                   $iH - height of the graph, [Optional]
;
; Return values..:  none
; Version........:  2
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; ===============================================================================================================
Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
    Local $max=_ArrayMax($arValues,1);compare numerically
    ;Local $values = UBound($arValues)
    Local $arColours[UBound($arNames)]
    Local $color
    For $i=0 To UBound($arValues)-1
        $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1)
        $arColours[$i]=$color
    Next
    ;set default values for the frame
    If $iX=-1 Then $iX=20
    If $iY=-1 Then $iY=20
    If $iW=-1 Then $iW=400
    If $iH=-1 Then $iH=400
    ;create frame for the chart
    $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)
    ;title
    GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Local $Canvas
    If IsString($arNames[1]) Then
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60)
        GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER)
            GUICtrlSetColor(-1,$arColours[$i]-0x444444)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$arColours[$i])
        Next
        GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30)
            GUICtrlSetColor(-1,0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf
    ;draw the bars
    GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0)
    For $i=0 To UBound($arValues)-1
        For $j=$Canvas[4]/2.5 To 0 Step -0.5
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i])
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i])
GUICtrlSetState(-1,2048)
        Next
    Next
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)
    For $i=0 To UBound($arValues)-1
        ;values from the top of the bars
        GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        GUICtrlSetColor(-1,0x002244)
        GUICtrlSetFont(-1, 7, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
 
    ;Y Axis
    For $i=0 To $Canvas[3] Step $Canvas[3]/5
        GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT)
        GUICtrlSetColor(-1,0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
EndFunc
#Region INTERNAL USE ONLY
Func _RoundUp($m)
    Local $rv = Round(Ceiling($m/10)*10,-1)
    Return $rv
EndFunc
 
Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE)
    Local $iXCanvas=$iX+$iDepthCanvas
    Local $iYCanvas=$iY+10+2*$iDepthCanvas
    Local $iWCanvas=$iW-2*$iDepthCanvas
    Local $iHCanvas=$iH-2*$iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
    ;create bg for the bars
    For $i=0 To $iDepthCanvas
        GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
GUICtrlSetState(-1,2048)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1)
GUICtrlSetState(-1,2048)
    ;horizontal grid
    For $i=0 To $iHCanvas Step $iHCanvas/5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)
GUICtrlSetState(-1,2048)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas)
GUICtrlSetState(-1,2048)
    Next
    Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2)
    Return $Canvas
EndFunc
#EndRegion INTERNAL USE ONLY

Share this post


Link to post
Share on other sites

Hi Taietel

Thanks very much thats alot cleaner than what i had done. I know im asking alot of questions of you and i thank you for your effort and time. Im trying to update the bar chart on the fly. Once its drawn then uodate some values in the graph after certain events. Is there a way to do this please?

Thanks in advance. Im trying to figure it out myself but so far having no joy.

jamie

@engjcowi:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
 
Global $arNames[12]
Global $arValues[12]
GUICreate("3D Bar Graph on Tabs - Example", 610, 410)
GUICtrlCreateTab(5, 5, 600, 400)
$Tab1 = GUICtrlCreateTabItem("Tab1")
$arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2)
For $i=0 To 11
$arValues[$i]=Random(0,200,1)
Next
_CreateBarChart("3D Bar Chart","Example 1",-1,30,560,360)
 
$Tab2 = GUICtrlCreateTabItem("Tab2")
For $i=0 To 11
   $arNames[$i]=$i+1
Next
For $i=0 To 11
$arValues[$i]=Random(0,200,1)
Next
_CreateBarChart("3D Bar Chart","Example 2",50,50,400,300)
 
$Tab3 = GUICtrlCreateTabItem("Tab3")
ReDim $arNames[16]
ReDim $arValues[16]
For $i=0 To 15
   $arNames[$i]=$i+1
Next
For $i=0 To 15
$arValues[$i]=Random(0,200,1)
Next
$arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2)
_CreateBarChart("3D Bar Chart","Example 3 - with legend",30,30,560,360)
 
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
 
While 1
Sleep(10)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
 
EndSwitch
WEnd
 
; #FUNCTION# ====================================================================================================
; Name...........:  _CreateBarChart
; Description....:  Create 3D bar graph with native AutoIt functions
; Syntax.........:  _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
; Parameters.....:  $sTitle1 - Title of the graph, [Optional]
;                  $sTitle2 - Subtitle of the graph, [Optional]
;                  $iX - left margin, [Optional]
;                  $iY - top margin, [Optional]
;                  $iW - width of the graph, [Optional]
;                  $iH - height of the graph, [Optional]
;
; Return values..:  none
; Version........:  2
; Author.........:  Mihai Iancu (taietel at yahoo dot com)
; ===============================================================================================================
Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400)
    Local $max=_ArrayMax($arValues,1);compare numerically
    ;Local $values = UBound($arValues)
    Local $arColours[UBound($arNames)]
    Local $color
    For $i=0 To UBound($arValues)-1
        $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1)
        $arColours[$i]=$color
    Next
    ;set default values for the frame
    If $iX=-1 Then $iX=20
    If $iY=-1 Then $iY=20
    If $iW=-1 Then $iW=400
    If $iH=-1 Then $iH=400
    ;create frame for the chart
    $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH)
    ;title
    GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER)
    GUICtrlSetColor(-1,0x002244)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Local $Canvas
    If IsString($arNames[1]) Then
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60)
        GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER)
            GUICtrlSetColor(-1,$arColours[$i]-0x444444)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$arColours[$i])
        Next
        GUICtrlCreateGroup("", -99, -99, 1, 1)
    Else
        $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60)
        For $i=0 To UBound($arNames)-1
            GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30)
            GUICtrlSetColor(-1,0x990000)
            GUICtrlSetFont(-1, 8, 800, 0, "Arial")
            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
        Next
    EndIf
    ;draw the bars
    GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0)
    For $i=0 To UBound($arValues)-1
        For $j=$Canvas[4]/2.5 To 0 Step -0.5
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i])
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i])
GUICtrlSetState(-1,2048)
        Next
    Next
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)
    For $i=0 To UBound($arValues)-1
        ;values from the top of the bars
        GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i])
        GUICtrlSetColor(-1,0x002244)
        GUICtrlSetFont(-1, 7, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
 
    ;Y Axis
    For $i=0 To $Canvas[3] Step $Canvas[3]/5
        GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT)
        GUICtrlSetColor(-1,0x990000)
        GUICtrlSetFont(-1, 8, 800, 0, "Arial")
        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
EndFunc
#Region INTERNAL USE ONLY
Func _RoundUp($m)
    Local $rv = Round(Ceiling($m/10)*10,-1)
    Return $rv
EndFunc
 
Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE)
    Local $iXCanvas=$iX+$iDepthCanvas
    Local $iYCanvas=$iY+10+2*$iDepthCanvas
    Local $iWCanvas=$iW-2*$iDepthCanvas
    Local $iHCanvas=$iH-2*$iDepthCanvas
    Local $BgColor2 = $BgColor - 0x333333
    ;create bg for the bars
    For $i=0 To $iDepthCanvas
        GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0)
        GUICtrlSetBkColor(-1, $BgColor)
        GUICtrlSetColor(-1, $BgColor2)
GUICtrlSetState(-1,2048)
    Next
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1)
GUICtrlSetState(-1,2048)
    ;horizontal grid
    For $i=0 To $iHCanvas Step $iHCanvas/5
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i)
GUICtrlSetState(-1,2048)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas)
GUICtrlSetState(-1,2048)
    Next
    Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2)
    Return $Canvas
EndFunc
#EndRegion INTERNAL USE ONLY


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

engjcowi, I'm sorry for the delay but I had (and still do) a lot of work.

Due to the fact that this example uses a lot of static controls (labels), when updating the whole chart is relatively slowly drawn.

Here is an example with GDI that updates the chart every second, and the images are saved for later use (png format):

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <Array.au3>
 
Opt('MustDeclareVars', 1)
_GDIPlus_Startup()
_Example()
While 1
Sleep(10)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
 
Func _Example()
;data array (some random values)
Local $aValues[11][3]
$aValues[0][0] = 10
 
Local $hGUI = GUICreate("3D Bar Chart in AutoIt (GDI+ style) - 2011 taietel", 420, 300)
GUISetState()
 
For $m=1 To 5
For $i = 1 To UBound($aValues) - 1
$aValues[$i][1] = Random(0, 100, 1)
Next
_3D_BarChart($hGUI, $aValues, "Example Chart no."&$m, "GDI+ attempt...")
Sleep(1000)
Next
EndFunc   ;==>_Main
 
Func _3D_BarChart($hGUI, $aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $iX = 10, $iY = 10, $iW = 400, $iH = 280, $iDepth = 30, $lBgColor = 0x80cacafe)
;coded by taietel
Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
 
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Local $hBmpBuff = $aResult[6]
 
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBmpBuff)
_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
 
;create canvas
Local $hBgBrush = _GDIPlus_BrushCreateSolid($lBgColor)
For $i = 0 To $iDepth Step 0.5
_GDIPlus_GraphicsFillRect($hGraphic, $i, $iDepth - $i, $iW - $iDepth, $iH - $iDepth, $hBgBrush)
_GDIPlus_BrushSetSolidColor($hBgBrush, $lBgColor)
Next
Local $hPen = _GDIPlus_PenCreate(0xF0808080)
_GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, 0, $iW, 0, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, $iW, $iH - $iDepth, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, $iH - 1, $iW - $iDepth, $iH - 1, $hPen)
 
_GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, 0, 0, $iDepth, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, 0, $iH, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iW, $iH - $iDepth, $iW - $iDepth, $iH, $hPen)
 
_GDIPlus_GraphicsDrawLine($hGraphic, 0, $iH, 0, $iDepth, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, $iDepth, 0, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iW - 1, 0, $iW - 1, $iH - $iDepth, $hPen)
 
Local $iMax = 0, $iMin = 0
For $i = 1 To $aArray[0][0]
If $iMax < $aArray[$i][1] Then $iMax = $aArray[$i][1]
If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1]
Next
 
Local $iFH = Floor($iH / 28)
$hBrush = _GDIPlus_BrushCreateSolid(0xF0EF0000)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 8)
_GDIPlus_BrushSetSolidColor($hBrush, 0xf8efefcc)
 
;create bars
For $j = 1 To $aArray[0][0]
$aArray[$j][2] = "0xFA" & Hex((Random(100, 180, 1) * 0x10000) + (Random(90, 140, 1) * 0x100) + Random(0, 150, 1), 6)
Local $iInalt = Int($aArray[$j][1] * ($iH - $iDepth) / $iMax)
For $i = 0 To Int(2 * $iDepth / 3) Step 0.5
If $i = Int(2 * $iDepth / 3) Then
_GDIPlus_BrushSetSolidColor($hBgBrush, $aArray[$j][2] + 0x111111)
Else
_GDIPlus_BrushSetSolidColor($hBgBrush, $aArray[$j][2])
EndIf
_GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]), $iH + $i - $iInalt - $iDepth + 10, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), $iInalt - 4, $hBgBrush)
Next
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]), $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth - 10, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush)
Next
_GDIPlus_StringFormatSetAlign($hFormat, 2)
$hFont = _GDIPlus_FontCreate($hFamily, $iFH + 1, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFF232323)
$tLayout = _GDIPlus_RectFCreate(1, 5 - 1, $iW - 5, 2 * $iFH)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, 0x55fefefe)
$tLayout = _GDIPlus_RectFCreate(0, 5, $iW - 5, 2 * $iFH)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
Local $hFontl = _GDIPlus_FontCreate($hFamily, $iFH - 1, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFF444444)
$tLayout = _GDIPlus_RectFCreate(1, 5 + Floor(2 * $iFH) - 1, $iW - 5, 2 * $iFH)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFontl, $tLayout, $hFormat, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, 0x55fefefe)
$tLayout = _GDIPlus_RectFCreate(0, 5 + Floor(2 * $iFH), $iW - 5, 2 * $iFH)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFontl, $tLayout, $hFormat, $hBrush)
 
Local $sImage = @ScriptDir & "\" & $sTitle & ".png";save it in case it is needed
_GDIPlus_ImageSaveToFile($hBmpBuff, $sImage)
Local $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImageRectRect($hGraphicGUI, $hBmpBuff, 0, 0, $iW, $iH, $iX, $iY, $iW, $iH)
 
; Clean up resources
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontDispose($hFontl)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hBgBrush)
_GDIPlus_BitmapDispose($hBmpBuff)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_GraphicsDispose($hGraphic)
Return $sImage
EndFunc   ;==>_3D_BarChart

You can modify to fit your needs. :D

Regards,

taietel

Share this post


Link to post
Share on other sites

Hi taitel

Thanks very much for all you help inthis. Ill have a play and see what i get.

Thanks again

Jamie


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

Another GDI+ atempts: one bar chart with legend, one simple pie and one exploded pie:

#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GDIPlus.au3>
#include <Array.au3>
Opt('MustDeclareVars', 1)
_GDIPlus_Startup()
_Example()

Func _Example()
;data array (some random values)
Local $aValues[11][3]
$aValues[0][0] = 10
Local $iM = 40
For $i = 1 To UBound($aValues) - 1
$aValues[$i][0] = "Grade " & $i
$aValues[$i][1] = Random(0, $iM, 1)
Next

Local $sImg
$sImg = _3D_PieChart($aValues, "Example 3D Pie Chart", $aValues[0][0] & " values array with random values [0..." & $iM & "]", True);exploded=True
$sImg = _3D_PieChart($aValues, "Example 3D Pie Chart", $aValues[0][0] & " values array with random values [0..." & $iM & "]");simple
$sImg = _3D_BarChart($aValues, "Example 3D Pie Chart", "10 values array with random values [0..." & $iM & "]")
Local $iYes = MsgBox(36,"Simple 3D Chart Example", "Press Yes if you want to open the generated PNG's"&@CRLF&"or No otherwise."&@CRLF&"It will generate 3 images.")
Switch $iYes
Case 6
ShellExecute($sImg)
Case 7
_Exit()
EndSwitch
EndFunc ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _3D_BarChart
; Description ...:
; Syntax ........: _3D_BarChart($aArray[, $sTitle = "Main title"[, $sSubTitle = "Subtitle"[, $iW = 500[, $iH = 350[,
; $lBgColor = 0x80efefef]]]]])
; Parameters ....: $aArray - An array of data
; |[i][0]=Label,
; |[i][1]=Value,
; |[i][2]=Colour.
; $sTitle - [optional] Title of the graph. Default is "Main title".
; $sSubTitle - [optional] Subtitle of the graph. Default is "Subtitle".
; $iW - [optional] Width of the canvas. Default is 500.
; $iH - [optional] Height of the canvas. Default is 350.
; $lBgColor - [optional] Background colour. Default is 0x80efefef.
; $sFolder - [optional] Folder path (without the leading "") where the images are saved. Default is @ScriptDir.
; Return values .: Image full path
; Return values .: None
; Author ........: Mihai Iancu (taietel at yahoo dot com)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _3D_BarChart($aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $iW = 500, $iH = 350, $lBgColor = 0x80efefef, $sFolder="")
If $sFolder="" Then $sFolder=@ScriptDir
Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $iDepth = 30
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW + 120, "int", $iH + 50, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($aResult[6])
_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
;create canvas
$hBrush = _GDIPlus_BrushCreateSolid($lBgColor)

Local $hPen = _GDIPlus_PenCreate(0x70101080)
Local $aPoints[5][2]
$aPoints[0][0] = 4
$aPoints[1][0] = 0
$aPoints[1][1] = 0
$aPoints[2][0] = $iW + 119
$aPoints[2][1] = 0
$aPoints[3][0] = $iW + 119
$aPoints[3][1] = $iH + 49
$aPoints[4][0] = 0
$aPoints[4][1] = $iH + 49
_GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)

_GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints, $hPen)
_GDIPlus_PenDispose($hPen)

Local $iMax = 0, $iMin = 0
For $i = 1 To $aArray[0][0]
If $iMax < $aArray[$i][1] Then $iMax = _Round($aArray[$i][1])
If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1]
$aArray[$i][2] = "0xFA" & Hex((Random(80, 190, 1) * 0x10000) + (Random(80, 190, 1) * 0x100) + Random(30, 190, 1), 6)
Next
Local $iFH = Floor($iH / 28)
$hBrush = _GDIPlus_BrushCreateSolid(0xF0EF0000)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
Local $x = ($iH + $iDepth - 60) / $aArray[0][0]
If $x < 20 Then
$hFont = _GDIPlus_FontCreate($hFamily, 8, 0)
Else
$hFont = _GDIPlus_FontCreate($hFamily, 10, 0)
EndIf
_GDIPlus_BrushSetSolidColor($hBrush, 0xf8efefcc)
;create bars
For $j = 1 To $aArray[0][0]
Local $iInalt = Int($aArray[$j][1] * ($iH - 2 * $iDepth) / $iMax)
For $i = 0 To Int(2 * $iDepth / 3) Step 0.5
If $i = Int(2 * $iDepth / 3) Then
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x111111)
Else
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2])
EndIf
If $aArray[$j][1] <> 0 Then
_GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + $i - $iInalt - $iDepth + 30, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), $iInalt, $hBrush)
Else
_GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + $i - $iDepth + 26, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), 4, $hBrush)
EndIf
Next
_GDIPlus_StringFormatSetAlign($hFormat, 1)
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0xd5222222)
If $aArray[$j][1] <> 0 Then
$tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth + 12, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH)
Else
$tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + Int(2 * $iDepth / 3) - $iDepth + 8, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH)
EndIf
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, 0xe0111111)
If $aArray[$j][1] <> 0 Then
$tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 9, $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth + 11, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH)
Else
$tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 9, $iH + Int(2 * $iDepth / 3) - $iDepth + 7, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH)
EndIf
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush)
Next

;title
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFont = _GDIPlus_FontCreate($hFamily, 12, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0x8fdedede)
$tLayout = _GDIPlus_RectFCreate(1, 10, $iW + 116, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, 0xee950000)
$tLayout = _GDIPlus_RectFCreate(0, 10 - 1, $iW + 115, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
;subtitle
$hFont = _GDIPlus_FontCreate($hFamily, 10, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFFb00000)
$tLayout = _GDIPlus_RectFCreate(1, 28, $iW + 115, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFont, $tLayout, $hFormat, $hBrush)

If $x < 20 Then
$hFont = _GDIPlus_FontCreate($hFamily, 6, 0)
Else
$hFont = _GDIPlus_FontCreate($hFamily, 8, 0)
EndIf
For $i = 1 To $aArray[0][0]
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$i][2])
_GDIPlus_GraphicsFillRect($hGraphic, $iW + 20, 50 + ($i - 1) * $x, 20, $x - 2, $hBrush)

_GDIPlus_StringFormatSetAlign($hFormat, 0)
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$i][2])
$tLayout = _GDIPlus_RectFCreate($iW + 45, 50 + Int($x / 3.5) + ($i - 1) * $x, 70, $x - 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$i][0], $hFont, $tLayout, $hFormat, $hBrush)
Next

Local $sImage = $sFolder & "" & $sTitle & "_bars.png"
_GDIPlus_ImageSaveToFile($aResult[6], $sImage)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($aResult[6])
_GDIPlus_GraphicsDispose($hGraphic)
Return $sImage
EndFunc ;==>_3D_BarChart

; #FUNCTION# ====================================================================================================================
; Name ..........: _3D_PieChart
; Description ...:
; Syntax ........: _3D_PieChart($aArray[, $sTitle = "Main title"[, $sSubTitle = "Subtitle"[, $bExplode = False[, $iW = 500[,
; $iH = 400[, $lBgColor = 0x80efefef]]]]]])
; Parameters ....: $aArray - An array of data
; |[i][0]=Label,
; |[i][1]=Value,
; |[i][2]=Colour.
; $sTitle - [optional] Title of the graph. Default is "Main title".
; $sSubTitle - [optional] Subtitle of the graph. Default is "Subtitle".
; $bExplode - [optional] True if exploded pie, otherwise False. Default is False.
; $iW - [optional] Width of the canvas. Default is 500.
; $iH - [optional] Height of the canvas. Default is 400.
; $lBgColor - [optional] Background colour. Default is 0x80efefef.
; $sFolder - [optional] Folder path (without the leading "") where the images are saved. Default is @ScriptDir.
; Return values .: Image full path
; Author ........: Mihai Iancu (taietel at yahoo dot com)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _3D_PieChart($aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $bExplode = False, $iW = 500, $iH = 400, $lBgColor = 0x80efefef, $sFolder="")
If $sFolder="" Then $sFolder=@ScriptDir
Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $iDepth = 30
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW + 1, "int", $iH + 50, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($aResult[6])
_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
;create canvas
$hBrush = _GDIPlus_BrushCreateSolid($lBgColor)
Local $aPoints[5][2]
$aPoints[0][0] = 4
$aPoints[1][0] = 0
$aPoints[1][1] = 0
$aPoints[2][0] = $iW
$aPoints[2][1] = 0
$aPoints[3][0] = $iW
$aPoints[3][1] = $iH + $iDepth
$aPoints[4][0] = 0
$aPoints[4][1] = $iH + $iDepth
_GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)
Local $hPen = _GDIPlus_PenCreate(0x70101080)
_GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints, $hPen)
_GDIPlus_PenDispose($hPen)
Local $iMax = 0, $iMin = 0
Local $iSum
For $i = 1 To $aArray[0][0]
If $iMax < $aArray[$i][1] Then $iMax = _Round($aArray[$i][1])
If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1]
$iSum += $aArray[$i][1]
$aArray[$i][2] = "0xFA" & Hex((Random(80, 190, 1) * 0x10000) + (Random(80, 190, 1) * 0x100) + Random(30, 190, 1), 6)
Next

_GDIPlus_BrushSetSolidColor($hBrush, 0xF0EF0000)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")

;title
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFont = _GDIPlus_FontCreate($hFamily, 12, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0x8fdedede)
$tLayout = _GDIPlus_RectFCreate(1, 10, $iW - 4, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, 0xee950000)
$tLayout = _GDIPlus_RectFCreate(0, 9, $iW - 5, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush)
;subtitle
$hFont = _GDIPlus_FontCreate($hFamily, 10, 0)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFFb00000)
$tLayout = _GDIPlus_RectFCreate(1, 28, $iW - 5, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFont, $tLayout, $hFormat, $hBrush)

Local $iInit = 5
For $i = 0 To $iDepth Step 0.5
For $j = 1 To $aArray[0][0]
Local $iAng = ($aArray[$j][1] * 360 / $iSum)
If $i > $iDepth - 1 Then
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] - $i * 0x202020)
Else
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x111111)
EndIf
If $bExplode Then
_GDIPlus_GraphicsFillPie($hGraphic, $iDepth, 110 - $i, $iW - 2 * $iDepth - 120, $iH - 2 * $iDepth / 1.2 - 78, $iInit, $iAng - 4, $hBrush)
Else
_GDIPlus_GraphicsFillPie($hGraphic, $iDepth, 110 - $i, $iW - 2 * $iDepth - 120, $iH - 2 * $iDepth / 1.2 - 78, $iInit, $iAng, $hBrush)
EndIf
$iInit += $iAng
Next
Next
#cs
;labels around the pie - still need some math adjustments...
Local $pi = 3.14159265358979, $iAngle
$iInit = 5
For $i = 1 To $aArray[0][0]
$iAng = ($aArray[$i][1] * 360 / $iSum)
Local $iRw = ($iW - 2 * $iDepth - 120) / 2 + 12.5
Local $iRh = ($iH - 2 * $iDepth / 1.2 - 78) / 2 +23
If $bExplode Then
$iAngle = Round(($iInit + ($iAng-2) / 2) * $pi / 180,1)
Else
$iAngle = Round(($iInit + $iAng / 2) * $pi / 180,1)
EndIf
;if we have 0 value, skip it:
If $aArray[$i][1] <> 0 Then _GDIPlus_GraphicsDrawString($hGraphic, $aArray[$i][1], _
Round($iRw * (Cos($iAngle) + 1))+$iDepth-20, _
Round($iRh * (Sin($iAngle) + 1))+50+$iDepth-15, _
"Arial", 8, $hFormat)

$iInit += $iAng
Next
#ce
;legend
Local $x = Int(($iH - $iDepth - 20) / $aArray[0][0])
If $x < 20 Then
$hFont = _GDIPlus_FontCreate($hFamily, 6, 0)
Else
$hFont = _GDIPlus_FontCreate($hFamily, 8, 0)
EndIf
For $j = 1 To $aArray[0][0]
For $i = 0 To 3 Step 0.5
If $i < 2.5 Then
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] - 0x111111)
Else
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x202020)
EndIf
_GDIPlus_GraphicsFillRect($hGraphic, $iW - 110 - 2 * $i, 60 + ($j - 1) * $x + $i, 30, $x - 5, $hBrush)
Next
Next
;value label on the small cube in the legend
For $j = 1 To $aArray[0][0]
_GDIPlus_StringFormatSetAlign($hFormat, 1)
_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0xee333333)
$tLayout = _GDIPlus_RectFCreate($iW - 113, 64 + ($j - 1) * $x + Int($x / 5), 30, $x - 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush)

_GDIPlus_BrushSetSolidColor($hBrush, 0xee222222)
$tLayout = _GDIPlus_RectFCreate($iW - 114, 63 + ($j - 1) * $x + Int($x / 5), 30, $x - 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_StringFormatSetAlign($hFormat, 0)

_GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2])
$tLayout = _GDIPlus_RectFCreate($iW - 70, 60 + ($j - 1) * $x + Int($x / 5), 119, $x - 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][0], $hFont, $tLayout, $hFormat, $hBrush)
Next

;save the image
Local $sImage
If $bExplode Then
$sImage = $sFolder & "" & $sTitle & "_expie.png"
Else
$sImage = $sFolder & "" & $sTitle & "_pie.png"
EndIf

_GDIPlus_ImageSaveToFile($aResult[6], $sImage)

_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($aResult[6])
_GDIPlus_GraphicsDispose($hGraphic)

Return $sImage
EndFunc ;==>_3D_PieChart

Func _Exit()
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit

Func _Round($iNumber)
If IsNumber($iNumber) Then $iNumber = Round(Ceiling($iNumber / 10) * 10, -1)
Return $iNumber
EndFunc ;==>_Round

In the 3D_Pie function I have comented the part that writes the values around the pie. You can delete the #cs and #ce to see the results, but still needs some thinking.

The script above outputs tree images (png) because I need them to be included in pdf reports. If you need to display on a GUI, just draw them with

_GDIPlus_GraphicsDrawImageRectRect.

Share this post


Link to post
Share on other sites

Looks awesome!!!
I'm looking to create a lines graph, but I find this example very useful!

Though, I got warning and error on Func _3D_BarChart: "warning: $ghGDIPDll: possibly used before declaration.",  " error: $ghGDIPDll: undeclared global variable."

 

Thanks!

Edited by The_Key_Maker

Share this post


Link to post
Share on other sites

@The_Key_Maker: replace $ghGDIPDll  with $__g_hGDIPDll, for example by adding below your #includes:

Global $ghGDIPDll=$g__h_GDIPDll

For line graphs, see for example here.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...