找回密码
 加入
搜索
查看: 3449|回复: 5

[原创] 3D叠柱数据图

[复制链接]
发表于 2017-8-6 15:12:17 | 显示全部楼层 |阅读模式
3D叠柱数据图
代码出处:
https://www.autoitscript.com/forum/topic/121546-3d-bar-graph/





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-8-6 15:12:49 | 显示全部楼层
本帖最后由 chzj589 于 2017-8-6 15:17 编辑

回复 1# chzj589

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-8-6 15:20:46 | 显示全部楼层
本帖最后由 chzj589 于 2017-8-13 19:55 编辑
回复  chzj589

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

第143楼
chzj589 发表于 2017-8-6 15:12


再次修改,接近实际运用



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +30 收起 理由
yamakawa + 30 好勤快。。。

查看全部评分

发表于 2017-8-7 00:24:46 | 显示全部楼层
我收集的


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

Global $ChartArray[0]

_GDIPlus_Startup()
$hGui = GUICreate("BalkenDiagramm", 550, 200)
GUISetState()
Global $array = [["voltagedrop [U] Bronze", 1.77], ["voltagedrop [U] 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)[2], $gHeight = WinGetPos($hGui)[3]
        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][0], $X + 5, $Y + 5 + $Abstand * $i)
                $MaxSize = _GetTextLabelWidth($Names[$i][0], "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][1] -= $start
                $MaxNumber = $Names[$i][1] > $MaxNumber ? $Names[$i][1] : $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][1] >= 0 Then
                        $white = _GDIPlus_BrushCreateSolid(0xFF4f81bd)
                        _GDIPlus_GraphicsFillRect($graphics, $X + $MaxSize + 6, $Y + $luecke * ($i + 1) + $luecke * $i + $i * $Balkenbreite, $MaxBalkenSize * $Names[$i][1], $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[UBound($ChartArray) + 1]
        $ChartArray[UBound($ChartArray) - 1] = $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[0], "long", $LOGPIXELSY)
        $intDeviceCap = $intDeviceCap[0]

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

        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[0], "hwnd", $hMyFont[0])

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

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

        Local $intLabelWidth = DllStructGetData($res, 1)

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-8-9 13:21:28 | 显示全部楼层
谢谢楼主分享,这个怎么用
发表于 2022-5-11 18:08:05 | 显示全部楼层
谢谢分享,学习学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-24 20:47 , Processed in 0.077217 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表