返回列表 发帖

[原创] 3D叠柱数据图

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





附件: 您需要登录才可以下载或查看附件。没有帐号?加入

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

回复 1# chzj589

修改木子的代码,竖叠柱型改为横条叠型。
代码出处:
http://www.autoitx.com/thread-55558-10-1.html
第143楼
附件: 您需要登录才可以下载或查看附件。没有帐号?加入

TOP

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

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

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


再次修改,接近实际运用



附件: 您需要登录才可以下载或查看附件。没有帐号?加入
1

评分人数

  • yamakawa

TOP

我收集的


  1. #include <GDIplus.au3>

  2. #include <GuiConstants.au3>

  3.  

  4. Global $ChartArray[0]

  5.  


  6. $hGui = GUICreate("BalkenDiagramm", 550, 200)


  7. Global $array = [["voltagedrop [U] Bronze", 1.77], ["voltagedrop [U] Stahl", 2.02]]

  8. _showChart($hGui, 20, 20, 484, 113, $array, 9, 1.65, 2.05)


  9.         If GUIGetMsg() = -3 Then

  10.                 Exit

  11.         EndIf


  12.  

  13. Func _showChart($hGui, $X, $Y, $Width, $Height, $Names, $Entrys, $start, $end)

  14.         Local $gWidth = WinGetPos($hGui)[2], $gHeight = WinGetPos($hGui)[3]

  15.         Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

  16.         Local $Abstand = 39

  17.         Local $Balkenbreite = 15

  18.         $white = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

  19.         _GDIPlus_GraphicsFillRect($graphics, $X, $Y, $Width, $Height, $white)

  20.         ;Zeichne Balkennamen

  21.         $MaxWidth = 0

  22.         For $i = 0 To UBound($Names) - 1 Step 1

  23.                 _GDIPlus_GraphicsDrawString($graphics, $Names[$i][0], $X + 5, $Y + 5 + $Abstand * $i)

  24.                 $MaxSize = _GetTextLabelWidth($Names[$i][0], "Arial", 10)

  25.                 If $MaxWidth < $MaxSize Then

  26.                         $MaxWidth = $MaxSize

  27.                 EndIf

  28.         Next

  29.         ;Zeichne kleine Balkentrenner

  30.         $MaxSize += 4

  31.         $count = 0

  32.         For $i = 0 To UBound($Names) - 1 Step 1

  33.                 _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $i * $Abstand, $X + $MaxSize + 4, $Y + 2 + $i * $Abstand)

  34.                 $count += 1

  35.         Next

  36.         _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $count * $Abstand, $X + $Width - 20, $Y + 2 + $count * $Abstand)

  37.         ;Gebe Breite

  38.         $luecke = (($Abstand - $Balkenbreite) / 2)

  39.         $MaxNumber = 0

  40.         For $i = 0 To UBound($Names) - 1 Step 1

  41.                 $Names[$i][1] -= $start

  42.                 $MaxNumber = $Names[$i][1] > $MaxNumber ? $Names[$i][1] : $MaxNumber

  43.         Next

  44.         ;Zeichne Balken

  45.         $MaxBalkenSize = ($Width - ($X + $MaxSize + 6)) / ($end - $start)

  46.         ;$MaxBalkenSize-=10

  47.         For $i = 0 To UBound($Names) - 1 Step 1

  48.                 If $Names[$i][1] >= 0 Then

  49.                         $white = _GDIPlus_BrushCreateSolid(0xFF4f81bd)

  50.                         _GDIPlus_GraphicsFillRect($graphics, $X + $MaxSize + 6, $Y + $luecke * ($i + 1) + $luecke * $i + $i * $Balkenbreite, $MaxBalkenSize * $Names[$i][1], $Balkenbreite, $white)

  51.                 EndIf

  52.         Next

  53.         ;Zeichne Texte

  54.         $oneEntry = ($end - $start) / $Entrys

  55.         $oneEntryWidth = ($Width - ($X + $MaxSize + 5)) / $Entrys

  56.         $MaxWidthText = 0

  57.         For $i = 0 To $Entrys Step 1

  58.                 $MaxSizeTmp = _GetTextLabelWidth(Round($start + $oneEntry * $i, 2), "Arial", 10)

  59.                 If $MaxWidthText < $MaxSizeTmp Then

  60.                         $MaxWidthText = $MaxSizeTmp

  61.                 EndIf

  62.         Next

  63.         $MaxWidthText /= 2

  64.         For $i = 0 To $Entrys Step 1

  65.                 _GDIPlus_GraphicsDrawString($graphics, Round($start + $oneEntry * $i, 2), $X + $MaxSize + 5 + $oneEntryWidth * $i - $MaxWidthText, $Y + 2 + $count * $Abstand + 4 + 5)

  66.                 _GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2 + $count * $Abstand + 4)

  67.         Next

  68.         ;Aktualisiere ChartArray

  69.         For $i = 0 To UBound($ChartArray) - 1 Step 1

  70.                 If $ChartArray[$i] = "" Then

  71.                         $ChartArray[$i] = $graphics

  72.                         Return $i

  73.                 EndIf

  74.         Next

  75.         ReDim $ChartArray[UBound($ChartArray) + 1]

  76.         $ChartArray[UBound($ChartArray) - 1] = $graphics

  77.         Return UBound($ChartArray) - 1

  78. EndFunc   ;==>_showChart

  79.  

  80. Func _deleteChart($hGui, $Number)

  81.         ;GUICtrlGetBkColor($hWnd)

  82.         _WinAPI_RedrawWindow($hGui)

  83.         _GDIPlus_GraphicsDispose($ChartArray[$Number])

  84.         $ChartArray[$Number] = ""

  85. EndFunc   ;==>_deleteChart

  86.  

  87. ;Author: [email]b8bboi@www.autoitscript.com[/email]

  88. Func _GetTextLabelWidth($s_WinText, $s_TextFont, $i_FontSize, $i_FontWeight = -1)

  89.         Local Const $DEFAULT_CHARSET = 0 ; ANSI character set

  90.         Local Const $OUT_CHARACTER_PRECIS = 2

  91.         Local Const $CLIP_DEFAULT_PRECIS = 0

  92.         Local Const $PROOF_QUALITY = 2

  93.         Local Const $FIXED_PITCH = 1

  94.         Local Const $RGN_XOR = 3

  95.         Local Const $LOGPIXELSY = 90

  96.  

  97.  

  98.         $h_WinTitle = "Get Label Width"

  99.         If $i_FontWeight = "" Or $i_FontWeight = -1 Then $i_FontWeight = 600 ; default Font weight

  100.         Local $h_GUI = GUICreate($h_WinTitle, 10, 10, -100, -100, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW)

  101.         Local $hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $h_GUI)

  102.  

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

  104.         $intDeviceCap = $intDeviceCap[0]

  105.  

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

  107.         $intFontHeight = -$intFontHeight[0]

  108.  

  109.         Local $hMyFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $intFontHeight, _

  110.         "int", 0, "int", 0, "int", 0, "int", $i_FontWeight, "int", 0, _

  111.         "int", 0, "int", 0, "int", $DEFAULT_CHARSET, _

  112.         "int", $OUT_CHARACTER_PRECIS, "int", $CLIP_DEFAULT_PRECIS, _

  113.         "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $s_TextFont)

  114.         DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hDC[0], "hwnd", $hMyFont[0])

  115.  

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

  117.  

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

  119.  

  120.         Local $intLabelWidth = DllStructGetData($res, 1)

  121.  

  122.         GUIDelete($h_GUI)

  123.         Return $intLabelWidth

  124. EndFunc   ;==>_GetTextLabelWidth

复制代码 高亮切换
附件: 您需要登录才可以下载或查看附件。没有帐号?加入
自己知道的,尽量告诉别人,自己不知道的,虚心学习

TOP

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

TOP

返回列表