|
楼主 |
发表于 2024-7-7 20:53:43
|
显示全部楼层
另一個單則線圖,可參考看看#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <StaticConstants.au3>
Local $aNumbers[6] = [-50, -60, -70, -60, -80, -90]
Local $iW = 600, $iH = 400
Local $Max = _ArrayMax($aNumbers), $Min = _ArrayMin($aNumbers)
;ConsoleWrite($Max & " " & $Min & @LF)
Local $iXAxisSpacing = ($iW - 60) / (UBound($aNumbers) - 1) ; Graphic ctrl will be positioned 40 pixels from LH border of GUI & 20 pixels from RH border of GUI (40+20=60).
Local $iYAxisSpacing = ($iH - 74) / ($Max - $Min) ; Graphic ctrl will be positioned 30 pixels from top border of GUI & 44 pixels from bottom border of GUI (30+44=74).
Local $hGui = GUICreate("The Graph", $iW, $iH)
; X-axis labels
For $i = 0 To UBound($aNumbers) - 1
GUICtrlCreateLabel($i + 1, ($i * $iXAxisSpacing) + 40 - 3, $iYAxisSpacing * ($Max - $Min + 1))
Next
; Y-axis labels
For $i = 0 To $Max - $Min
GUICtrlCreateLabel($Max - $i, 4, $iYAxisSpacing * $i + 30 - 5)
Next
; Graph's Name
GUICtrlCreateLabel("Graph's Name - Numbers vs. Equal Intervals", $iW / 2 - 200, $iH - 25, 400, 23, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800)
; Create Graphic Control
$idCtrlGraphic = GUICtrlCreateGraphic(40, 30, $iW - 60, $iH - 74)
; Graph area outline
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, (UBound($aNumbers) - 1) * $iXAxisSpacing, $iYAxisSpacing * ($Max - $Min))
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xCCCCCC) ; Set light-gray line colour
; X-axis lines
For $i = 0 To UBound($aNumbers) - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, ($i * $iXAxisSpacing), $iYAxisSpacing * ($Max - $Min) + 3)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, ($i * $iXAxisSpacing), 0)
Next
; Y-axis lines
For $i = 1 To $Max - $Min - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, 0, $iYAxisSpacing * $i)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, (UBound($aNumbers) - 1) * $iXAxisSpacing, $iYAxisSpacing * $i)
Next
; Plot Graph
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000FF) ; Set 0x0000FF(blue) line colour
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, 0, ($Max - $aNumbers[0]) * $iYAxisSpacing)
For $i = 0 To UBound($aNumbers) - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_LINE, ($i) * $iXAxisSpacing, ($Max - $aNumbers[$i]) * $iYAxisSpacing)
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_DOT, ($i) * $iXAxisSpacing, ($Max - $aNumbers[$i]) * $iYAxisSpacing)
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
雙折線圖#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <StaticConstants.au3>
Local $iW = 600, $iH = 400 ;圖表寬高設定
Local $aNumbers1[6] = [-50, -60, -70, -60, -70, -80] ;第一條折線圖
Local $aNumbers2[6] = [-50, -50, -60, -50, -60, -110] ;第二條折線圖
Local $Number_Max[2]=[0,0]
Local $Number_Min[2]=[0,0]
Local $Max1 = _ArrayMax($aNumbers1), $Min1 = _ArrayMin($aNumbers1)
Local $Max2 = _ArrayMax($aNumbers2), $Min2 = _ArrayMin($aNumbers2)
$Number_Max[0]= $Max1
$Number_Max[1]= $Max2
$Number_Min[0]= $Min1
$Number_Min[1]= $Min2
Local $Max = _ArrayMax($Number_Max), $Min = _ArrayMin($Number_Min)
;ConsoleWrite($Max & " " & $Min & @LF)
Local $iXAxisSpacing = ($iW - 60) / (UBound($aNumbers1) - 1) ; Graphic ctrl will be positioned 40 pixels from LH border of GUI & 20 pixels from RH border of GUI (40+20=60).
Local $iYAxisSpacing = ($iH - 74) / ($Max - $Min) ; Graphic ctrl will be positioned 30 pixels from top border of GUI & 44 pixels from bottom border of GUI (30+44=74).
Local $hGui = GUICreate("The Graph", $iW, $iH)
; X-axis labels
For $i = 0 To UBound($aNumbers1) - 1
GUICtrlCreateLabel($i + 1, ($i * $iXAxisSpacing) + 40 - 3, $iYAxisSpacing * ($Max - $Min + 1))
Next
; Y-axis labels
Local $line_display = 0
For $i = 0 To $Max - $Min
$line_display= Mod($i ,2 )
If $line_display = 0 then
GUICtrlCreateLabel($Max - $i, 4, $iYAxisSpacing * $i + 30 - 5)
EndIf
Next
; Graph's Name
GUICtrlCreateLabel("Graph's Name - Numbers vs. Equal Intervals", $iW / 2 - 200, $iH - 25, 400, 23, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800)
; Create Graphic Control
$idCtrlGraphic = GUICtrlCreateGraphic(40, 30, $iW - 60, $iH - 74)
; Graph area outline
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, (UBound($aNumbers1) - 1) * $iXAxisSpacing, $iYAxisSpacing * ($Max - $Min))
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xCCCCCC) ; Set light-gray line colour
; X-axis lines
For $i = 0 To UBound($aNumbers1) - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, ($i * $iXAxisSpacing), $iYAxisSpacing * ($Max - $Min) + 3)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, ($i * $iXAxisSpacing), 0)
Next
; Y-axis lines
For $i = 1 To $Max - $Min - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, 0, $iYAxisSpacing * $i)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, (UBound($aNumbers1) - 1) * $iXAxisSpacing, $iYAxisSpacing * $i)
Next
; Plot Graph
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000FF) ; Set 0x0000FF(blue) line colour
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, 0, ($Max - $aNumbers1[0]) * $iYAxisSpacing)
For $i = 0 To UBound($aNumbers1) - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_LINE, ($i) * $iXAxisSpacing, ($Max - $aNumbers1[$i]) * $iYAxisSpacing)
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_DOT, ($i) * $iXAxisSpacing, ($Max - $aNumbers1[$i]) * $iYAxisSpacing)
Next
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFF0000) ; Set 0x0000FF(blue) line colour
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_MOVE, 0, ($Max - $aNumbers2[0]) * $iYAxisSpacing)
For $i = 0 To UBound($aNumbers2) - 1
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_LINE, ($i) * $iXAxisSpacing, ($Max - $aNumbers2[$i]) * $iYAxisSpacing)
GUICtrlSetGraphic($idCtrlGraphic, $GUI_GR_DOT, ($i) * $iXAxisSpacing, ($Max - $aNumbers2[$i]) * $iYAxisSpacing)
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
|
|