Что нового

Рисуем график в Autoit

dumoed

Знающий
Сообщения
34
Репутация
5
Версия AutoIt
3.3.14.0
Версия
3.3.14.0
Пример с данными, подгружаемыми из файла
Код:
#include "GraphGDIPlus.au3"
#include <File.au3>
#include <Array.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("USD Rate:",800,600)
GUISetOnEvent(-3,"_Exit")
GUISetState()

;----- Create Graph area ----- left, right , lenght, hight, colors may be
$Graph = _GraphGDIPlus_Create($GUI,50,20,730,520,0xFF000000,0xFF88B3DD)

;Create var for txt
$FilePath = ("d:\rate.txt")
global $arr=FileReadToArray($FilePath) ; Читает указанный файл построчно в массив.

$max=_Ubound ($arr); получаем индекс последнего элемента в массиве, фактически макимальное количество элементов в массиве

;----- Set X axis range from 0 to 31 -----, 1st... 2nd максимальное знач по х 3ий количество пробелов между максим числами по хб 4 - число знаков после запятой
_GraphGDIPlus_Set_RangeX($Graph, 1,$max,$max-1,1,0)
; set y range
_GraphGDIPlus_Set_RangeY($Graph, 30,80,10,1,1)

;grid
_GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE)
_GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE)


;$Label1 = GUICtrlCreateLabel("Latest: "&$arr[$max], 600 , 100 , 155, 14); 1 - x 2 - y, 3 -lenght, 4 hight
_Draw_Graph() ;----- Draw the graph -----





While 1
    Sleep(1000)
WEnd

Func _UBound($a)

   local $i

   For $i=UBound($a) - 1 to 0 Step -1
      If StringLen($a[$i])>  0 Then ExitLoop
   Next
    Return $i

EndFunc

Func _Draw_Graph()
    ;----- Set line color and size -----
    _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87)
    _GraphGDIPlus_Set_PenSize($Graph,2)

    ;----- draw lines -----
    $First = True
    For $i = 0 to $max Step 1
            ; read arr with find first 4 digits, dot, 2 digits, dot, 2 dig, dot, space ^s, 2 dig, ":" , 2 dig , space double tos and replace them with nothing
    $y=StringRegExpReplace( $arr[$i],'(?m)^[0-9]{4}[.][0-9]{2}[.][0-9]{2}[^s][0-9]{2}[:][0-9]{2}[^s]',"")
;MsgBox ("","" ,"before = "&$arr[$i]&" after ="&$y)

        If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y)
        $First = False

        _GraphGDIPlus_Plot_Line($Graph,$i,$y)
        _GraphGDIPlus_Refresh($Graph)

    Next

EndFunc


Func _Exit()
    ;----- close down GDI+ and clear graphic -----
    _GraphGDIPlus_Delete($GUI,$Graph)
    Exit
EndFunc
 

Вложения

  • GraphGDIPlus.au3
    29 КБ · Просмотры: 11
  • rate.txt
    348 байт · Просмотры: 9
Последнее редактирование:

Prog

Продвинутый
Сообщения
537
Репутация
65
В GraphGDIPlus.au3 нужно добавить
Код:
#include <WinAPI.au3>
Если свернуть и развернуть окно, текст Latest: время пропадает.
 
Автор
D

dumoed

Знающий
Сообщения
34
Репутация
5
WinAPI.au3 добавил, Latest пока закомментировал
 
Верх