本帖最后由 水木子 于 2017-7-22 21:24 编辑
抽空改了一下,现在柱状图项目可以同时包含正值和负值堆叠。
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iLineleft = 50, $iLineTop = 300, $iLineWidth = 770, $iLineHeight = 560
Global $iItemWidth = 25, $iItemHeight
Global $iX = 15
Global $aItem[10] = ['50,80,-140', '70,80,100', '90,-40,-80', '130,50,70', '120,-50,70,-80', '150', '-130,80', '90,70,-80,70', '-150,80,80', '120,30,40']
Global $aItemID[0]
GUICreate('', 800, 600)
$Graphic1 = GUICtrlCreateGraphic(10, 10, 780, 580, 0x00800000)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $iLineleft, 20)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iLineleft, $iLineHeight)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $iLineleft, $iLineTop)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iLineWidth, $iLineTop)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, 128)
For $i = 0 To 10
GUICtrlCreateLabel(($i - 5) * 50 & '-', 20, (550 - $i * 50), 40, 20, 0x0002 + 0x0200)
GUICtrlSetFont(-1, 12, 400)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
Next
For $i = 0 To UBound($aItem) - 1
$aValue = StringSplit($aItem[$i], ',', 2)
Local $iItemTop1
Local $iItemTop2 = $iLineTop + 10
Local $iItemTop3 = $iLineTop + 10 + 1
Local $iItemTop4 = ''
For $z = 0 To UBound($aValue) - 1
ReDim $aItemID[UBound($aItemID) + 1]
$iItemHeight = Abs($aValue[$z])
If $aValue[$z] > 0 Then
$iItemTop2 -= $iItemHeight
$iItemTop1 = $iItemTop2
Else
If $iItemTop4 == '' Then
$iItemTop1 = $iItemTop3
Else
$iItemTop3 += Abs($aValue[$iItemTop4])
$iItemTop1 = $iItemTop3
EndIf
$iItemTop4 = $z
EndIf
$aItemID[UBound($aItemID) - 1] = GUICtrlCreateLabel('', 100 + ($i * ($iItemWidth + $iX)), $iItemTop1, $iItemWidth, $iItemHeight, 0x01 + 0x0200)
GUICtrlSetBkColor(-1, '0x' & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2))
Next
Next
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $aItemID[0] To $aItemID[UBound($aItemID) - 1]
MsgBox(0, 0, $nMsg - $aItemID[0] + 1)
EndSwitch
WEnd
|