chzj589 发表于 2017-8-6 15:12:17

3D叠柱数据图

3D叠柱数据图
代码出处:
https://www.autoitscript.com/forum/topic/121546-3d-bar-graph/





chzj589 发表于 2017-8-6 15:12:49

本帖最后由 chzj589 于 2017-8-6 15:17 编辑

回复 1# chzj589

修改木子的代码,竖叠柱型改为横条叠型。
代码出处:
http://www.autoitx.com/thread-55558-10-1.html
第143楼

chzj589 发表于 2017-8-6 15:20:46

本帖最后由 chzj589 于 2017-8-13 19:55 编辑

回复chzj589

修改木子的代码,竖叠柱型改为横条叠型。
代码出处:

第143楼
chzj589 发表于 2017-8-6 15:12 http://www.autoitx.com/images/common/back.gif

再次修改,接近实际运用



lpxx 发表于 2017-8-7 00:24:46

我收集的


#include <GDIplus.au3>
#include <GuiConstants.au3>

Global $ChartArray

_GDIPlus_Startup()
$hGui = GUICreate("BalkenDiagramm", 550, 200)
GUISetState()
Global $array = [["voltagedrop Bronze", 1.77], ["voltagedrop Stahl", 2.02]]
_showChart($hGui, 20, 20, 484, 113, $array, 9, 1.65, 2.05)
While Sleep(10)
        If GUIGetMsg() = -3 Then
                Exit
        EndIf
WEnd

Func _showChart($hGui, $X, $Y, $Width, $Height, $Names, $Entrys, $start, $end)
        Local $gWidth = WinGetPos($hGui), $gHeight = WinGetPos($hGui)
        Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
        Local $Abstand = 39
        Local $Balkenbreite = 15
        $white = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
        _GDIPlus_GraphicsFillRect($graphics, $X, $Y, $Width, $Height, $white)
        ;Zeichne Balkennamen
        $MaxWidth = 0
        For $i = 0 To UBound($Names) - 1 Step 1
                _GDIPlus_GraphicsDrawString($graphics, $Names[$i], $X + 5, $Y + 5 + $Abstand * $i)
                $MaxSize = _GetTextLabelWidth($Names[$i], "Arial", 10)
                If $MaxWidth < $MaxSize Then
                        $MaxWidth = $MaxSize
                EndIf
        Next
        ;Zeichne kleine Balkentrenner
        $MaxSize += 4
        $count = 0
        For $i = 0 To UBound($Names) - 1 Step 1
                _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $i * $Abstand, $X + $MaxSize + 4, $Y + 2 + $i * $Abstand)
                $count += 1
        Next
        _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $count * $Abstand, $X + $Width - 20, $Y + 2 + $count * $Abstand)
        ;Gebe Breite
        $luecke = (($Abstand - $Balkenbreite) / 2)
        $MaxNumber = 0
        For $i = 0 To UBound($Names) - 1 Step 1
                $Names[$i] -= $start
                $MaxNumber = $Names[$i] > $MaxNumber ? $Names[$i] : $MaxNumber
        Next
        ;Zeichne Balken
        $MaxBalkenSize = ($Width - ($X + $MaxSize + 6)) / ($end - $start)
        ;$MaxBalkenSize-=10
        For $i = 0 To UBound($Names) - 1 Step 1
                If $Names[$i] >= 0 Then
                        $white = _GDIPlus_BrushCreateSolid(0xFF4f81bd)
                        _GDIPlus_GraphicsFillRect($graphics, $X + $MaxSize + 6, $Y + $luecke * ($i + 1) + $luecke * $i + $i * $Balkenbreite, $MaxBalkenSize * $Names[$i], $Balkenbreite, $white)
                EndIf
        Next
        ;Zeichne Texte
        $oneEntry = ($end - $start) / $Entrys
        $oneEntryWidth = ($Width - ($X + $MaxSize + 5)) / $Entrys
        $MaxWidthText = 0
        For $i = 0 To $Entrys Step 1
                $MaxSizeTmp = _GetTextLabelWidth(Round($start + $oneEntry * $i, 2), "Arial", 10)
                If $MaxWidthText < $MaxSizeTmp Then
                        $MaxWidthText = $MaxSizeTmp
                EndIf
        Next
        $MaxWidthText /= 2
        For $i = 0 To $Entrys Step 1
                _GDIPlus_GraphicsDrawString($graphics, Round($start + $oneEntry * $i, 2), $X + $MaxSize + 5 + $oneEntryWidth * $i - $MaxWidthText, $Y + 2 + $count * $Abstand + 4 + 5)
                _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2 + $count * $Abstand + 4)
        Next
        ;Aktualisiere ChartArray
        For $i = 0 To UBound($ChartArray) - 1 Step 1
                If $ChartArray[$i] = "" Then
                        $ChartArray[$i] = $graphics
                        Return $i
                EndIf
        Next
        ReDim $ChartArray
        $ChartArray = $graphics
        Return UBound($ChartArray) - 1
EndFunc   ;==>_showChart

Func _deleteChart($hGui, $Number)
        ;GUICtrlGetBkColor($hWnd)
        _WinAPI_RedrawWindow($hGui)
        _GDIPlus_GraphicsDispose($ChartArray[$Number])
        $ChartArray[$Number] = ""
EndFunc   ;==>_deleteChart

;Author: b8bboi@www.autoitscript.com
Func _GetTextLabelWidth($s_WinText, $s_TextFont, $i_FontSize, $i_FontWeight = -1)
        Local Const $DEFAULT_CHARSET = 0 ; ANSI character set
        Local Const $OUT_CHARACTER_PRECIS = 2
        Local Const $CLIP_DEFAULT_PRECIS = 0
        Local Const $PROOF_QUALITY = 2
        Local Const $FIXED_PITCH = 1
        Local Const $RGN_XOR = 3
        Local Const $LOGPIXELSY = 90


        $h_WinTitle = "Get Label Width"
        If $i_FontWeight = "" Or $i_FontWeight = -1 Then $i_FontWeight = 600 ; default Font weight
        Local $h_GUI = GUICreate($h_WinTitle, 10, 10, -100, -100, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW)
        Local $hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $h_GUI)

        Local $intDeviceCap = DllCall("gdi32.dll", "long", "GetDeviceCaps", "int", $hDC, "long", $LOGPIXELSY)
        $intDeviceCap = $intDeviceCap

        Local $intFontHeight = DllCall("kernel32.dll", "long", "MulDiv", "long", $i_FontSize, "long", $intDeviceCap, "long", 72)
        $intFontHeight = -$intFontHeight

        Local $hMyFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $intFontHeight, _
        "int", 0, "int", 0, "int", 0, "int", $i_FontWeight, "int", 0, _
        "int", 0, "int", 0, "int", $DEFAULT_CHARSET, _
        "int", $OUT_CHARACTER_PRECIS, "int", $CLIP_DEFAULT_PRECIS, _
        "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $s_TextFont)
        DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hDC, "hwnd", $hMyFont)

        Local $res = DllStructCreate("int;int")

        Local $ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC, "str", $s_WinText, "long", StringLen($s_WinText), "ptr", DllStructGetPtr($res))

        Local $intLabelWidth = DllStructGetData($res, 1)

        GUIDelete($h_GUI)
        Return $intLabelWidth
EndFunc   ;==>_GetTextLabelWidth

canghaisui 发表于 2017-8-9 13:21:28

谢谢楼主分享,这个怎么用

kodin 发表于 2022-5-11 18:08:05

谢谢分享,学习学习
页: [1]
查看完整版本: 3D叠柱数据图