yohoboy 发表于 2024-7-7 02:54:45

CHART- 圖表顯示[已解決]

本帖最后由 yohoboy 于 2024-7-7 20:45 编辑

目前卡在一個問題,嘗試修改 從 Scrolling Line Graph UDF - AutoIt Example Scripts - AutoIt Forums (autoitscript.com)   這個代碼內容,所需如下
1.共有四條線(1及2線為顯示數值折線,3為第一警戒線1,4為第二警戒線2)
主要卡在GUI顯示後需要不斷刷新才能顯示圖表,是否有方法可以一開始載入GUI時一併載入初始值圖表(也就是第1及2線初始值為0,第3線持續顯示60從頭到尾,第四線持續顯示80從頭到尾)
然後等候外部數值輸入後,再修改第一及第二線數值?




#include <SLG.au3>
Opt('GuiOnEventMode', 1)
Const $cRed = 0xFFFF0000, $cGreen = 0xFF00FF00, $cBlue = 0xFF00ACFF,$cYellow = 0xFFFFFF00

$GUI = GUICreate("GDI-CHART", 628, 297, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent(-3, '_Exit')
$Increments = 20 ;設定X軸數量
$G_Line1 = _SLG_CreateGraph($GUI, 18, 18, 596, 257, 0, 100, $Increments,$cBlue) ;設定主線
_SLG_SetGridLineColor($G_Line1, 0xFF005C5C) ;格線顏色
_SLG_SetYRange($G_Line1, 10, 90)
$G_Line2 = _SLG_AddLine($G_Line1, $cGreen) ;設定副線
$G_Line3 = _SLG_AddLine($G_Line1, $cYellow) ;設定警戒線1
$G_Line4 = _SLG_AddLine($G_Line1, $cRed) ;設定警戒線2

GUISetState()

While 1
      $Line1_temp = Random(0,100)
      $Line2_temp = Random(0,100)
    _SLG_SetLineValue($G_Line1, $Line1_temp,$G_Line1)
      _SLG_SetLineValue($G_Line1, $Line2_temp,$G_Line2)
      _SLG_SetLineValue($G_Line1, 60,$G_Line3) ;設定警戒線1值
      _SLG_SetLineValue($G_Line1, 80,$G_Line4) ;設定警戒線2值

   _SLG_UpdateGraph($G_Line1)
    Sleep(1000)
WEnd

Func _Exit()
    Exit
EndFunc


yohoboy 发表于 2024-7-7 17:24:59

目前用偷吃步的方式,先建立圖表及初始值,看看有沒有大德還可以改更好一點。
#include <SLG.au3>
Opt('GuiOnEventMode', 1)
Const $cRed = 0xFFFF0000, $cGreen = 0xFF00FF00, $cBlue = 0xFF00ACFF,$cYellow = 0xFFFFFF00

$GUI = GUICreate("GDI-CHART", 628, 297, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent(-3, '_Exit')
$Increments = 20 ;設定X軸數量
$G_Line1 = _SLG_CreateGraph($GUI, 18, 18, 600, 250, -105, 0, $Increments,$cBlue) ;設定主線
_SLG_SetGridLineColor($G_Line1, 0xFF005C5C) ;格線顏色
$G_Line2 = _SLG_AddLine($G_Line1, $cGreen) ;設定副線
$G_Line3 = _SLG_AddLine($G_Line1, $cYellow) ;設定警戒線1
$G_Line4 = _SLG_AddLine($G_Line1, $cRed) ;設定警戒線2
GUISetState()

create_chart()

Func create_chart()
        For $i =0 To -21 Step -1
                _SLG_SetLineValue($G_Line1, 0, $G_Line1)
                _SLG_SetLineValue($G_Line1, 0, $G_Line2)
                _SLG_SetLineValue($G_Line1, -60, $G_Line3) ;設定警戒線1值
                _SLG_SetLineValue($G_Line1, -80, $G_Line4) ;設定警戒線2值
                _SLG_UpdateGraph($G_Line1)
        Next
EndFunc

While 1
        $Line1_temp = Random(-100,0)
        $Line2_temp = Random(-100,0)
    _SLG_SetLineValue($G_Line1, $Line1_temp,$G_Line1)
        _SLG_SetLineValue($G_Line1, $Line2_temp,$G_Line2)
        _SLG_SetLineValue($G_Line1, -60,$G_Line3) ;設定警戒線1值
        _SLG_SetLineValue($G_Line1, -80,$G_Line4) ;設定警戒線2值
   _SLG_UpdateGraph($G_Line1)
   Sleep(2000)
WEnd

Func _Exit()
    Exit
EndFunc

afan 发表于 2024-7-7 18:07:02

没看udf,不造是不是这意思
#include <SLG.au3>
Opt('GuiOnEventMode', 1)
Const $cRed = 0xFFFF0000, $cGreen = 0xFF00FF00, $cBlue = 0xFF00ACFF, $cYellow = 0xFFFFFF00

$GUI = GUICreate("GDI-CHART", 628, 297, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent(-3, '_Exit')
$Increments = 20 ;設定X軸數量
$G_Line1 = _SLG_CreateGraph($GUI, 18, 18, 600, 250, -105, 0, $Increments, $cYellow)
_SLG_SetGridLineColor($G_Line1, 0xFF005C5C) ;格線顏色
$G_Line4 = _SLG_AddLine($G_Line1, $cRed)
GUISetState()
create_chart()

$G_Line2 = _SLG_AddLine($G_Line1, $cGreen)
$G_Line3 = _SLG_AddLine($G_Line1, $cBlue)

Func create_chart()
        For $i = 0 To $Increments
                _SLG_SetLineValue($G_Line1, -60, $G_Line1) ;設定警戒線1值
                _SLG_SetLineValue($G_Line1, -80, $G_Line4) ;設定警戒線2值
                _SLG_UpdateGraph($G_Line1)
        Next
EndFunc   ;==>create_chart

While 1
        $Line1_temp = Random(-100, 0)
        $Line2_temp = Random(-100, 0)
        _SLG_SetLineValue($G_Line1, $Line1_temp, $G_Line2)
        _SLG_SetLineValue($G_Line1, $Line2_temp, $G_Line3)
        _SLG_UpdateGraph($G_Line1)
        Sleep(500)
WEnd

Func _Exit()
        Exit
EndFunc   ;==>_Exit

yohoboy 发表于 2024-7-7 20:45:25

afan 发表于 2024-7-7 18:07
没看udf,不造是不是这意思

感謝A大的協助,剛好這個是所需的,沒想到把初始值換另一個就好了,原來要等候數值出來後在顯示折線,不如一開始先將警戒值設定好就好了。本帖結案。

yohoboy 发表于 2024-7-7 20:53:43

另一個單則線圖,可參考看看#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <StaticConstants.au3>

Local $aNumbers = [-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) * $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 = [-50, -60, -70, -60, -70, -80] ;第一條折線圖
Local $aNumbers2 = [-50, -50, -60, -50, -60, -110] ;第二條折線圖
Local $Number_Max=
Local $Number_Min=

Local $Max1 = _ArrayMax($aNumbers1), $Min1 = _ArrayMin($aNumbers1)
Local $Max2 = _ArrayMax($aNumbers2), $Min2 = _ArrayMin($aNumbers2)
$Number_Max= $Max1
$Number_Max= $Max2
$Number_Min= $Min1
$Number_Min= $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) * $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) * $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

邪恶海盗 发表于 2024-7-12 21:22:59

太高级了,看不懂....
--------------------------

chzj589 发表于 2024-7-15 10:24:37

yohoboy 发表于 2024-7-7 20:53
另一個單則線圖,可參考看看

雙折線圖

不错,应用一下



resethdd 发表于 2024-7-18 00:02:58

感觉以后会用到,留个脚印,感谢{:1_173:}
页: [1]
查看完整版本: CHART- 圖表顯示[已解決]