Sign in to follow this  
Followers 0
Phaser

Plotting values to a graph

19 posts in this topic

Hi Guys

I have been fidling trying to create a graph on my GUI not really having any luck as I don't know what I am doing to be honest. I have read the few threads there are on graphs etc and tried to understand the code and manipulate it to my needs but no joy.

Can someone tell me what I should be looking for, I have 2 values so need an X and Y if I could set the values of the X Y scales to display my data as it grows that would be cool.

The values I have are to see the entries of my data input if for example if I had 200 inputs at that time I would like to see a line sort of like a market data output, a staggered line going from left to right up down depending on the inputs. The X data to start would need to be

100

75

50

25

0

-25

-50

-75

-100

If my data gets bigger than 100 I would like just the + 4 values to grow with it, if my data gows below -100 I would like only those 4 values to change

And the Y axis

10 20 30 40 50 60 being the amount of data added, as more data is added I would like the graph to stay the same size but the 60 would now become the max and that figure divided by 6 to show the Y axis values, eg lets say I have added 200 items, thats more than 60 so I would like the Y axis values to change to

34 68 102 136 170 204

Is this possible with Autoit?

Share this post


Link to post
Share on other sites

Phaser,

I have used andybiochem's GraphGDIPlus UDF with success - have you tried it? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

have you tried it?

 

Yes thats the one I am trying to change to suit my needs but have no idea what the _GammaFunction is for as it returns the Y value, its over my head sadly but his was the best I could find here.

Share this post


Link to post
Share on other sites

_GammaFunction is the function that "creates" the data to be drawn. You need to replace it with your own function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I think I am on the right path but cannot seem to make the graph dynamic, atleast as dynamic as I want it that is. Here is my test file.

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)

$GUI = GUICreate("Test", 260, 270, 1018,0)

;----- Create Graph area -----
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
;----- Set X axis range from -5 to 5 -----
   _GraphGDIPlus_Set_RangeX($Graph,0,100,5,1); horizontal figures
   _GraphGDIPlus_Set_RangeY($Graph,-5,100,5,1,1); vertical figures

GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUISetState()

Local $value=0,$counter=0

While 1
    Sleep(1000)
WEnd

Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value+1

;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,100,5,1)
_GraphGDIPlus_Set_RangeY($Graph,0,100,5,1,1)

;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc



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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,1)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)

EndFunc



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

If you run it you will see the X&Y values are fixed at 0 to 100, what I want it to do is grow with the amount of data being entered, I've tried making it dynamic but at that point the graph X&Ys do change to suit BUT the line stands still so you cant see what its doing, hope that makes sense.

Share this post


Link to post
Share on other sites

I hate to bump a thread but I am stumped now, any ideas?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi. Maybe something like this:

#include "GraphGDIPlus.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("",600,600)
GUISetOnEvent(-3,"_Exit")
GUISetState()

;----- Create Graph area -----
$Graph = _GraphGDIPlus_Create($GUI,40,30,530,520,0xFF000000,0xFF88B3DD)



Local $iXRange=5,$iYRange=5

;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,-$iXRange,$iYRange,10,1,1)
_GraphGDIPlus_Set_RangeY($Graph,-$iYRange,$iYRange,10,1,1)

;----- Set Y axis range from -5 to 5 -----
_GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE)
_GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE)



_GraphGDIPlus_Set_PenSize($Graph,1)
_GraphGDIPlus_Plot_Start($Graph,-$iXRange,-$iYRange)

for $i= -$iXRange to ($iXRange*2) Step 0.050
if $i>$iXRange or $i >$iYRange Then
_GraphGDIPlus_Set_RangeX($Graph,-$iXRange,$i+1,10,1,1)
_GraphGDIPlus_Set_RangeY($Graph,-$iYRange,$i+1,10,1,1)
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE)
_GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE)
_GraphGDIPlus_Plot_Start($Graph,-$iXRange,-$iYRange)
_GraphGDIPlus_Plot_Line($Graph,$i,$i)
_GraphGDIPlus_Refresh($Graph)
EndIf
_GraphGDIPlus_Plot_Line($Graph,$i,$i)
_GraphGDIPlus_Refresh($Graph)

Next

;----- Draw the graph -----
;~ _Draw_Graph()

While 1
    Sleep(100)
WEnd



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

    ;----- draw lines -----
    $First = True
    For $i = -5 to 5 Step 0.005
        $y = _GammaFunction($i)
        If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y)
        $First = False
        _GraphGDIPlus_Plot_Line($Graph,$i,$y)
        _GraphGDIPlus_Refresh($Graph)
    Next
EndFunc



Func _GammaFunction($iZ)
    $nProduct = ((2^$iZ) / (1 + $iZ))
    For $n = 2 to 1000
        $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n))
    Next
    Return (1/$iZ) * $nProduct
EndFunc



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

or 

#include "GraphGDIPlus.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("",600,600)
GUISetOnEvent(-3,"_Exit")
GUISetState()

;----- Create Graph area -----
$Graph = _GraphGDIPlus_Create($GUI,40,30,530,520,0xFF000000,0xFF88B3DD)



Local $iXRange=5,$iYRange=5

;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,-$iXRange,$iYRange,10,1,1)
_GraphGDIPlus_Set_RangeY($Graph,-$iYRange,$iYRange,10,1,1)

;----- Set Y axis range from -5 to 5 -----
_GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE)
_GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE)



_GraphGDIPlus_Set_PenSize($Graph,1)
_GraphGDIPlus_Plot_Start($Graph,-$iXRange,-$iYRange)

for $i= -$iXRange to ($iXRange*2) Step 0.050
if $i>$iXRange or $i >$iYRange Then
_GraphGDIPlus_Set_RangeX($Graph,-$iXRange,$i+1,10,1,1)
_GraphGDIPlus_Set_RangeY($Graph,-$iYRange,$i+1,10,1,1)
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE)
_GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE)
_GraphGDIPlus_Plot_Start($Graph,-$iXRange,-$iYRange)
_GraphGDIPlus_Plot_Line($Graph,$i+1,$i+1)
_GraphGDIPlus_Refresh($Graph)
EndIf

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

Next

;----- Draw the graph -----
;~ _Draw_Graph()

While 1
    Sleep(100)
WEnd



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

    ;----- draw lines -----
    $First = True
    For $i = -5 to 5 Step 0.005
        $y = _GammaFunction($i)
        If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y)
        $First = False
        _GraphGDIPlus_Plot_Line($Graph,$i,$y)
        _GraphGDIPlus_Refresh($Graph)
    Next
EndFunc



Func _GammaFunction($iZ)
    $nProduct = ((2^$iZ) / (1 + $iZ))
    For $n = 2 to 1000
        $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n))
    Next
    Return (1/$iZ) * $nProduct
EndFunc



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

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Many thanks Danyfirex, any chance you could modify my existing code as I don't really understand what you have done, please

Share this post


Link to post
Share on other sites

mmm

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)

$GUI = GUICreate("Test", 260, 270, Default,Default)


;----- Create Graph area -----
Local $XMax=100,$YMax=100 ;We declare Our max values
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,0,$YMax,5,1,1); vertical figures


GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUISetState()

Global $value=0,$counter=0

While 1
    Sleep(1000)
WEnd


Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value+1

;----- Set X axis range from -5 to 5 -----
if $counter =$YMax Then
$XMax+=20
$YMax=$XMax
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1)
_GraphGDIPlus_Set_RangeY($Graph,0,$YMax,5,1,1)
_GraphGDIPlus_Plot_Start($Graph,0,0)
_GraphGDIPlus_Plot_Line($Graph,$counter,$value)
_GraphGDIPlus_Refresh($Graph)
EndIf

sleep(60); Not Need Only for View 


;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc



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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,0)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)

EndFunc



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

Also it could be Better.

Saludos

Share this post


Link to post
Share on other sites

Thank you very much, that is perfect, I can now understand it much better, thanks for your help Danyfirex you are a star.

Share this post


Link to post
Share on other sites

You're Welcome.

 

Saludos

Share this post


Link to post
Share on other sites

Sorry for slow reply but the forum wasn't working for some time, anyway, there is a slight issue with the code it doesn't go into a negative view, I mean if the value goes into a minus the graph doesn't go with it, I have added an array for the test example, when you run it you will see what I mean, also, when the graph grows the current up/down graph just goes into a flat line/slope?

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Test", 260, 270, Default,Default)
;----- Create Graph area -----
Local $XMax=100,$YMax=100 ;We declare Our max values
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,0,$YMax,5,1); vertical figures

GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUISetState()

Global $value1[130]=[2,4,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1],$counter=0,$value

While 1
    Sleep(1000)
WEnd


Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value1[$counter]

;----- Set X axis range from -5 to 5 -----
if $counter =$YMax Then
$XMax+=20
$YMax=$XMax
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1)
_GraphGDIPlus_Set_RangeY($Graph,0,$YMax,5,1)
_GraphGDIPlus_Plot_Start($Graph,0,0)
_GraphGDIPlus_Plot_Line($Graph,$counter,$value)
_GraphGDIPlus_Refresh($Graph)
EndIf

sleep(60); Not Need Only for View


;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc



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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,0)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)

EndFunc



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

I hope you see what I mean, thanks for looking again.

Share this post


Link to post
Share on other sites

Only invert the code. study the code that I did and You'll find the way to do it.

 

Saludos

Share this post


Link to post
Share on other sites

Hi again

OK still struggling with this graph business. The horizontal axis is sort of OK (it flatlines and loses the past history which is a shame) I am trying to get the vertical axis working, if you run what I have you will see it moves up and down sort of OK but what I really want it to do is use the LOWEST it hits as the lowest value and the highest it hits as the HIGHEST value, I just can't get my head around it.

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Test", 260, 270, Default,Default)
;----- Create Graph area -----
Local $XMax=100,$YMin=0,$YMax=100 ;We declare Our max values
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,$YMin,$YMax,5,1); vertical figures

GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUICtrlCreateLabel("CurrentValue", 10, 40)
$currentvalue = GUICtrlCreateInput("na", 100, 39, 30, 16)

GUISetState()

Global $value1[130]=[-2,4,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1],$counter=0,$value

While 1
    Sleep(1000)
WEnd

Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value1[$counter]

;----- Set X axis range from -5 to 5 -----
if $counter = $XMax Then
$XMax = $XMax+20
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Plot_Start($Graph,0,0)
_GraphGDIPlus_Plot_Line($Graph,$counter,$value)
_GraphGDIPlus_Refresh($Graph)
EndIf

if $value <= $YMin Then
$YMin = $value-10;$YMin-20
$YMax = $YMax-10
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_RangeY($Graph,$YMin,$YMax,5,1)
_GraphGDIPlus_Plot_Start($Graph,0,0)
_GraphGDIPlus_Plot_Line($Graph,$counter,$value)
_GraphGDIPlus_Refresh($Graph)
EndIf

if $value >= $YMax Then
$YMin = $value+10
$YMax = $YMax+10
_GraphGDIPlus_Clear($Graph)
_GraphGDIPlus_Set_RangeY($Graph,$YMin,$YMax,5,1)
_GraphGDIPlus_Plot_Start($Graph,0,0)
_GraphGDIPlus_Plot_Line($Graph,$counter,$value)
_GraphGDIPlus_Refresh($Graph)
EndIf

sleep(50); Not Need Only for View

;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc

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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,0)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)
      front()
EndFunc

Func front()

    GUICtrlSetData($currentvalue, $value)

EndFunc

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

I would also like it to keep the data/graph formation it had before it adjusted itself, hope someone much cleverer than me can do something, I have tried as you can see, thanks for any help

Share this post


Link to post
Share on other sites

OK thanks to everyone who read and held back from helping, really, it made me use my head, although it's taken a good few days I have made it work how I want it BUT I think it may NOT be the best way to redraw the graph. In the example below I have an array with 260 values, this is just a test script, in my real data entry script I am adding the values to an array that obviousley grows with the data added, this array "could" end up very big (in the 10,000s) and with each refresh after adjustment of the X or Y scales it may start slowing down, is it best to build the array? write to a file? or what?

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Test", 260, 270, Default,Default)
;----- Create Graph area -----
Local $XMax=100,$YMin=0,$YMax=100 ;We declare Our max values
Local $maxdown=0,$maxup=100
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,$YMin,$YMax,5,1); vertical figures

GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUICtrlCreateLabel("CurrentValue", 10, 40)
$currentvalue = GUICtrlCreateInput("na", 100, 39, 30, 16)

GUISetState()

Global $value1[260]=[-2,4,3,1,7,27,12,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,112,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,-2,4,3,1,7,27,12,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,112,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1],$counter=0,$counter2=0,$value

While 1
    Sleep(1000)
WEnd

Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value1[$counter]

;----- Set X axis range from -5 to 5 -----
if $counter = $XMax Then
   $XMax = $XMax+20
   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter2 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter2)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

if $value <= $YMin Then
   $YMin = $value-10;$YMin-20
   $YMax = $YMax-10

      If $value < $maxdown Then
         $maxdown = $value
      EndIf

   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeY($Graph,$maxdown,$maxup,5,1)
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter3 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter3)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

if $value >= $YMax Then
   $YMin = $value+10
   $YMax = $YMax+10

      If $value > $maxup Then
         $maxup = $value
      EndIf

   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeY($Graph,$maxdown,$maxup,5,1)
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter4 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter4)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

sleep(50); Not Need Only for View

;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc

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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,0)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)
      front()
EndFunc

Func front()

    GUICtrlSetData($currentvalue, $value)

EndFunc

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

Thanks for looking, but please reply if you have a suggestion for me, if you run the above you will see the X Y adjust themselves, the $value is what I am storing in an array on my real tool, the above is only for testing with the 260 values in the provided array.

Share this post


Link to post
Share on other sites

I think a option could be, if you adjustment then plus to the time some values.

 

saludos

Share this post


Link to post
Share on other sites

I think a option could be, if you adjustment then plus to the time some values.

 

saludos

Hi, sorry but I don't understand what you mean ?

Share this post


Link to post
Share on other sites

Maybe this:

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

HotKeySet("{ESC}", "killit")
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Test", 260, 270, Default,Default)
;----- Create Graph area -----
Local $XMax=100,$YMin=0,$YMax=100 ;We declare Our max values
Local $maxdown=0,$maxup=100
$Graph = _GraphGDIPlus_Create($GUI,70,70,130,120,0xFF000000,0xFF88B3DD)
Global $iSleep=50
;----- Set X axis range from -5 to 5 -----
_GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,$YMin,$YMax,5,1); vertical figures

GUISetOnEvent($GUI_EVENT_CLOSE, "killit")
$okbutton = GUICtrlCreateButton("Start", 50, 220, 60) ;ID 4
GUICtrlSetOnEvent($okbutton, "goforit")
$cancelbutton = GUICtrlCreateButton("Close", 140, 220, 60) ; ID 5
GUICtrlSetOnEvent($cancelbutton, "killit")
$checkbox = GUICtrlCreateCheckbox("Tick to pause (press Close to exit or Start to step)", 10, 8, 250, 20)
GUICtrlCreateLabel("CurrentValue", 10, 40)
$currentvalue = GUICtrlCreateInput("na", 100, 39, 30, 16)

GUISetState()

Global $value1[260]=[-2,4,3,1,7,27,12,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,112,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,-2,4,3,1,7,27,12,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,112,-9,-4,11,21,98,27,112,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1,3,1,7,27,12,-9,-4,11,21,98,27,12,-29,34,76,-1],$counter=0,$counter2=0,$value

While 1
    Sleep(1000)
WEnd

Func goforit()
While 1; the main loop, everything happens within here

$counter = $counter+1
$value = $value1[$counter]

;----- Set X axis range from -5 to 5 -----
if $counter = $XMax Then
   $XMax = $XMax+20
    $iSleep+=10
   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeX($Graph,0,$XMax,5,1); horizontal figures
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter2 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter2)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

if $value <= $YMin Then
   $YMin = $value-10;$YMin-20
   $YMax = $YMax-10

      If $value < $maxdown Then
         $maxdown = $value
      EndIf

   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeY($Graph,$maxdown,$maxup,5,1)
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter3 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter3)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

if $value >= $YMax Then
   $YMin = $value+10
   $YMax = $YMax+10

      If $value > $maxup Then
         $maxup = $value

      EndIf

   _GraphGDIPlus_Clear($Graph)
   _GraphGDIPlus_Set_RangeY($Graph,$maxdown,$maxup,5,1)
   _GraphGDIPlus_Plot_Start($Graph,0,0)

      $i = 0
      Do
         $counter4 = $value1[$i]
         _GraphGDIPlus_Plot_Line($Graph,$i,$counter4)
         _GraphGDIPlus_Refresh($Graph)
      $i = $i+1
      Until $i = $counter

EndIf

sleep($iSleep); Not Need Only for View

;----- Draw the graph -----
_Draw_Graph()

If BitAnd(GUICtrlRead($checkbox), $GUI_CHECKED) = True Then
    ExitLoop
EndIf

WEnd ; end of main loop

EndFunc

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

    ;----- draw lines -----
      If $counter = 1 Then
      _GraphGDIPlus_Plot_Start($Graph,0,0)
      EndIf
      _GraphGDIPlus_Plot_Line($Graph,$counter,$value)
      _GraphGDIPlus_Refresh($Graph)
      front()
EndFunc

Func front()

    GUICtrlSetData($currentvalue, $value)

EndFunc

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

look $iSleep Variable.

Saludos

Share this post


Link to post
Share on other sites

Hi again, I don't think I explained properly, my concern is this bit

 

in my real data entry script I am adding the values to an array that obviousley grows with the data added, this array "could" end up very big (in the 10,000s) and with each refresh after adjustment of the X or Y scales it may start slowing down, is it best to build the array? write to a file? or what?

 

In my real data entry software I start with

$value1[1]=[0.1] (on the first entry I replace the 0.1)

If $counter = 0 Then
   _GraphGDIPlus_Plot_Start($Graph,0,0)
   _ArrayPush($value1,$value,1)
EndIf

Then every time I add data I add to the array like this

_ArrayAdd($value1,$value)

This way I can rerun ALL previous data to keep the graphs history in view, it all works perfect BUT after a lot of data it will slow down as the array grows, how big can the array get before it grinds to a hault? should I do it like this OR is there a better way to remember the previous data so the graph displays everything all the time?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0