andybiochem Posted August 30, 2008 Share Posted August 30, 2008 (edited) UPDATED 14/10/09EDIT - also see my new GDI+ version of this UDFHi!I've created a lot of programs/calculators that use graphs, and have been meaning to create a simple UDF to allow quick creation of graphs and their x / y axes.Here is what I have done so far, I'll add other features as I come up with them.... hopefully it should end up with things like bar-charts, scatter plots etc in the future.FUNCTIONS:_Graph_Create ...............creates the graph area_Graph_Clear..................removes any plotted items_Graph_Delete.................deletes graph and labels_Graph_SetRange_X.........sets the x axis_Graph_SetRange_Y.........sets the Y axis_Graph_Plot_Start............moves the starting plot position (equivalent to $GUI_GR_MOVE)_Graph_Plot_Line.............draws a lineNEW FUNCTIONS (14/10/09):_Graph_Plot_Point.............plots small square around x,y_Graph_Plot_Dot...................plots a single pixel at x,y_Graph_Set_PenSize................sets next pen size_Graph_Set_Color..................sets the colour/background colour of next drawing_Graph_Plot_Bar_X.................plots a bar chart bar along the x axis_Graph_Plot_Bar_Y.................plots a bar chart bar along the y axis_Graph_SetGrid_X..................sets the x axis grid_Graph_SetGrid_Y..................sets the y axis gridThe UDF:Graph UDF.au3expandcollapse popup#include-once #include <GUIConstantsEx.au3> ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _Graph_Create($iLeft,$iTop,$iWidth,$iHeight) ; Parameters ....: $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Colour ; [15] Fill Colour ; ======================================================================================= Func _Graph_Create($iLeft,$iTop,$iWidth,$iHeight,$hColourBorder = 0x000000,$hColorFill = 0xFFFFFF) $hWnd = GUICtrlCreateGraphic($iLeft,$iTop,$iWidth+1,$iHeight+1) GUICtrlSetColor(-1,$hColourBorder) GUICtrlSetBkColor(-1,$hColorFill) Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Dim $aGraphArray[16] = ["",$hWnd,$iLeft,$iTop,$iWidth,$iHeight,0,1,0,1, _ $ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY,$hColourBorder,$hColorFill] Return $aGraphArray EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _Graph_Delete(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; ======================================================================================= Func _Graph_Delete(ByRef $aGraphArray) ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- delete graphic control ----- GUICtrlDelete($aGraphArray[1]) ;----- close array ----- $aGraphArray = 0 EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Clear ; Description ...: Clears graph content ; Syntax.........: _Graph_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; ======================================================================================= Func _Graph_Clear(ByRef $aGraphArray) GUICtrlDelete($aGraphArray[1]) $aGraphArray[1] = GUICtrlCreateGraphic($aGraphArray[2],$aGraphArray[3], _ $aGraphArray[4]+1,$aGraphArray[5]+1) GUICtrlSetBkColor(-1,0xFFFFFF) GUICtrlSetColor(-1,0x000000) EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_SetRange_X ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _Graph_SetRange_X(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _Graph_SetRange_X(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("",(($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5],1,5) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10,$aGraphArray[4] / $iXTicks,13,1) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p",(($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6],$aGraphArray[7],$aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_SetRange_Y ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _Graph_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _Graph_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)),5,1) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6,30,13,2) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i],StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)),$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _Graph_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _Graph_Plot_Start(ByRef $aGraphArray,$iX,$iY) ;----- MOVE pen to start point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_MOVE, _ _Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ _Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _Graph_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _Graph_Plot_Line(ByRef $aGraphArray,$iX,$iY) ;----- Draw line from previous point to new point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_LINE, _ _Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ _Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _Graph_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _Graph_Plot_Point(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_DOT, _ _Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ _Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _Graph_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _Graph_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_PIXEL, _ _Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ _Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Set_Color ; Description ...: sets the color for the next drawing ; Syntax.........: _Graph_Set_Color(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKCOLOR) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $hColor - the color of the next item ; $hBkGrdColor - the background color of the next item ; ======================================================================================== Func _Graph_Set_Color(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKCOLOR) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_COLOR,$hColor,$hBkGrdColor) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _Graph_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iSize - size of pen line ; ======================================================================================== Func _Graph_Set_PenSize(ByRef $aGraphArray,$iSize = 1) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_PENSIZE,$iSize) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Bar_X ; Description ...: Draws bar chart bar from the x axis ; Syntax.........: _Graph_Plot_Bar_X(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iStart - the x axis value for start of bar (in x axis units) ; $iWidth - width of the bar (in x axis units) ; $nYValue - 'height' of the bar (in y axis units) ; $hColor - Bar border colour ; $hBkGrdColor - Bar fill colour ; ======================================================================================== Func _Graph_Plot_Bar_X(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR) ;----- Draw Bar for BarChart Application ----- _Graph_Set_Color($aGraphArray,$hColor,$hBkGrdColor) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT, _ _Graph_Reference_Pixel("x",$iStart,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ ;x $aGraphArray[5]+1, _ Round(_Graph_Reference_Pixel("x",$iStart + $iWidth,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) - _ ;width _Graph_Reference_Pixel("x",$iStart,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) + 1), _ - $aGraphArray[5] + _Graph_Reference_Pixel("y",$nYValue,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) - 1) ;height ;- redraw axis in case coloured - _Graph_Set_Color($aGraphArray,$aGraphArray[14],$GUI_GR_NOBKCOLOR) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT,0,0,$aGraphArray[4]+1,$aGraphArray[5]+1) ;- set colour back to default - _Graph_Set_Color($aGraphArray,0x000000,$GUI_GR_NOBKCOLOR) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Bar_Y ; Description ...: Draws bar chart bar from the y axis ; Syntax.........: _Graph_Plot_Bar_Y(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iStart - the y axis value for start of bar (in y axis units) ; $iWidth - width of the bar (in y axis units) ; $nXValue - 'length' of the bar (in x axis units) ; $hColor - Bar border colour ; $hBkGrdColor - Bar fill colour ; ======================================================================================== Func _Graph_Plot_Bar_Y(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR) ;----- Draw Bar for BarChart Application ----- _Graph_Set_Color($aGraphArray,$hColor,$hBkGrdColor) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT, _ 0, _ ;x _Graph_Reference_Pixel("y",$iStart + $iWidth,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ ;y _Graph_Reference_Pixel("x",$nYValue,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) + 1, _ ;width _Graph_Reference_Pixel("y",$iStart,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) - _ ;height _Graph_Reference_Pixel("y",$iStart + $iWidth,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) + 1) ;- redraw axis in case coloured - _Graph_Set_Color($aGraphArray,$aGraphArray[14],$GUI_GR_NOBKCOLOR) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT,0,0,$aGraphArray[4]+1,$aGraphArray[5]+1) ;- set colour back to default - _Graph_Set_Color($aGraphArray,0x000000,$GUI_GR_NOBKCOLOR) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_SetGrid_X ; Description ...: Adds X gridlines. ; Syntax.........: _Graph_SetGrid(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining color of grid. Default is a light gray ; ======================================================================================= Func _Graph_SetGrid_X(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) _Graph_Set_Color($aGraphArray,$hColor,$GUI_GR_NOBKCOLOR) Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT, _ ;rectangle _Graph_Reference_Pixel("x",$i,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ ;x 1, _ ;y 1, _ ;width $aGraphArray[5] - 1) ;height Next EndSelect _Graph_Set_Color($aGraphArray,0x000000) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_SetGrid_Y ; Description ...: Adds Y gridlines. ; Syntax.........: _Graph_SetGrid(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining color of grid. Default is a light gray ; ======================================================================================= Func _Graph_SetGrid_Y(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) _Graph_Set_Color($aGraphArray,$hColor,$GUI_GR_NOBKCOLOR) Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_RECT, _ ;rectangle 1, _ ;x _Graph_Reference_Pixel("y",$i,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ ;y $aGraphArray[4] - 1, _ ;width 1) ;height Next EndSelect _Graph_Set_Color($aGraphArray,0x000000) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _Graph_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; ======================================================================================== Func _Graph_Refresh(ByRef $aGraphArray) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_REFRESH) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow))))) Case "p" Return ($iValue / ($iTotalPixels/ ($iHigh - $iLow))) + $iLow EndSwitch EndFuncExample usage:Notes:Thanks to joseLB for looking at adding grid lines to the graph area. I hope you don't mind, but I changed the approach quite a bit. I wanted to keep it in line with the 'standardised' approach of the other functions.Actually, I wish I'd approached this UDF in a completely different way now, but it's used throughout my statistical software and major changes would render those programs useless! argh!Feel free to comment / criticise! Edited October 22, 2009 by andybiochem mLipok 1 - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Andreik Posted August 30, 2008 Share Posted August 30, 2008 Just tested and work fine. Very easy to use. Link to comment Share on other sites More sharing options...
andybiochem Posted August 30, 2008 Author Share Posted August 30, 2008 (edited) Just tested and work fine. Very easy to use. Gosh, that was quick!! Thank you for testing!I've just noticed something 'unusual' about the example screen-shot (now removed) I gave above...the x axis labels are 2, 4, 6, 8, 11, 13, 15...Thought I'd explain why this happens before ppl comment:...The label names are calculated from the specified upper and lower limits in _Graph_SetRange_X, and the floats are rounded by the function. So make sure you specify a rounding value if you want to avoid this anomaly!!! Edited October 14, 2009 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
MartiniThePilot Posted October 16, 2008 Share Posted October 16, 2008 I just looked for an UDF like this to display simple measured values (FPS and CPU time). Your sample worked like a charme Thanx! Martini Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted October 16, 2008 Share Posted October 16, 2008 Hi!I've created a lot of programs/calculators that use graphs, and have been meaning to create a simple UDF to allow quick creation of graphs and their x / y axes.Here is what I have done so far, I'll add other features as I come up with them.... hopefully it should end up with things like bar-charts, scatter plots etc in the future.Looking forward to that!Thanks for sharing. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
DirtDBaK Posted October 20, 2008 Share Posted October 20, 2008 I would suggest adding grid lines. Cant test it on this school computer but I will look into it later. [center][/center] Link to comment Share on other sites More sharing options...
Gyzmok Posted May 14, 2009 Share Posted May 14, 2009 Well done ! Works very fine. Thanks D2charkeeper = No more 'expired characters' in D2.File Date Changer = Change the file date(s), attributes and the filename case of multiple files @ once.Updater_full = Copy/Update your autoitscripts, pictures, .mp3, .avi etc ... subdirs from your PC to your memory stick or to your external harddisk. Now with scheduling and logging.Questmapper Link to comment Share on other sites More sharing options...
joseLB Posted September 1, 2009 Share Posted September 1, 2009 Hi Andy, great job! Simple to use and straigth to the point!I did an AU3 to graph about 750 points in almost no time with your UDF and your example.I was tooking lots of time trying to do it with GDI+ functions, but labeling X, Y is a nightmare...I just would like to suggest one more function for labeling + grid_Graph_Labels(title, Xlabel,Ylabel,Xgrid,Ygrid, grid intensity) where: title= string with title that appears centered at top of graph Xlabel= string with text that appears centered at bottom of graph Ylabel= string with text that appears over the x axis Xgrid= 0 -> no grid, other numbers = multiple/submultiple of Xtics, where: 1= one vertical line over each Xtick, 0.5= one vertical line over each half Xtick, 2= one vertical line over each 2 Xtick, and so on... (3, 4,...) Ygrid= 0 -> no grid, other numbers = multiple/submultiple of Ytics, where: 1= one vertical line over each Ytick, 0.5= one vertical line over each half Ytick, 2= one vertical line over each 2 Ytick, and so on... (3, 4,...) Grid Intensity= 0 to 255 for X/Y grid (gray scale )ThanksJose Link to comment Share on other sites More sharing options...
joseLB Posted September 4, 2009 Share Posted September 4, 2009 (edited) Hi Andy I did a Grid Function for your UDF! I hope you like it. All others interested in grids! Add this code to Andy's UDF so you can do Grids on your graphics ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Grid ; Description ...: makes X and/or Y grid. ; Syntax.........: _Graph_Grid($graph, $Xlines, $Ylines, $color=0xf0f0f0) ; Parameters ....: $Grap - the array returned from _Graph_Create ; $Xlines - # of grid lines per _Graph_SetRange_X Xticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no X grid ; $Ylines - # of grid lines per _Graph_SetRange_Y Yticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no Y grid ; $color - [optional] RGB value, defining color of grid. Default is a light gray, 0xf0f0f0 ; ======================================================================================= Func _Graph_Grid($graph, $Xticks=1, $Yticks=1, $color=0xf0f0f0) GUICtrlSetGraphic($graph[1], $GUI_GR_COLOR, $color) If $Xticks > 0 Then For $k = $graph[6]+$Xticks to $graph[7] Step $Xticks _Graph_Plot_Start($graph,$k,$graph[8]) ;grade _Graph_Plot_Line($graph,$k,$graph[9]) Next EndIf If $Yticks > 0 Then For $k = $graph[8]+$Yticks to $graph[9] Step $Yticks _Graph_Plot_Start($graph,$graph[6],$k) ;grade _Graph_Plot_Line($graph,$graph[7],$k) Next EndIf GUICtrlSetGraphic($graph[1], $GUI_GR_COLOR,0) EndFuncRegards Jose Edited September 4, 2009 by joseLB Link to comment Share on other sites More sharing options...
ctl3d32 Posted September 6, 2009 Share Posted September 6, 2009 Hi, Keep improving this UDF, don't give up. Graphics are a must for data visualization. This UDF rock's. Thanks you very much, ctl3d32 Link to comment Share on other sites More sharing options...
MartiniThePilot Posted September 10, 2009 Share Posted September 10, 2009 Hi,thanks for the grid function. To display graphics within an AutoIt GUI you may probably also have a look to imbed one of the (flash) graphic engines here. Ciao, Martini Link to comment Share on other sites More sharing options...
Gyzmok Posted September 23, 2009 Share Posted September 23, 2009 The grid is a very nice add. Thanks. D2charkeeper = No more 'expired characters' in D2.File Date Changer = Change the file date(s), attributes and the filename case of multiple files @ once.Updater_full = Copy/Update your autoitscripts, pictures, .mp3, .avi etc ... subdirs from your PC to your memory stick or to your external harddisk. Now with scheduling and logging.Questmapper Link to comment Share on other sites More sharing options...
joseLB Posted October 7, 2009 Share Posted October 7, 2009 thanks for all incentives.So, here are 2 new small functions and the complete Graph.udf (nothing changed for old users, just added these 2 functions:_Graph_LineColor --> changes color for all future drawed lines up to a new _Graph_LineColor. _Graph_Mark --> start to put "+" marks at the end of each drawed line.expandcollapse popup#include-Once ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _Graph_Create($iLeft,$iTop,$iWidth,$iHeight) ; Parameters ....: $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; ======================================================================================= Func _Graph_Create($iLeft,$iTop,$iWidth,$iHeight) $hWnd = GUICtrlCreateGraphic($iLeft,$iTop,$iWidth+1,$iHeight+1) GUICtrlSetBkColor(-1,0xFFFFFF) GUICtrlSetColor(-1,0x000000) Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Dim $aGraphArray[14] = ["",$hWnd,$iLeft,$iTop,$iWidth,$iHeight,0,1,0,1,$ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY] Return $aGraphArray EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _Graph_Delete(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; ======================================================================================= Func _Graph_Delete(ByRef $aGraphArray) ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- delete graphic control ----- GUICtrlDelete($aGraphArray[1]) ;----- close array ----- $aGraphArray = 0 EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_Clear ; Description ...: Clears graph content ; Syntax.........: _Graph_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; ======================================================================================= Func _Graph_Clear(ByRef $aGraphArray) GUICtrlDelete($aGraphArray[1]) $aGraphArray[1] = GUICtrlCreateGraphic($aGraphArray[2],$aGraphArray[3],$aGraphArray[4]+1,$aGraphArray[5]+1) GUICtrlSetBkColor(-1,0xFFFFFF) GUICtrlSetColor(-1,0x000000) EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_SetRange_X ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _Graph_SetRange_X(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _Graph_SetRange_X(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("",(($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5],1,5) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10,$aGraphArray[4] / $iXTicks,13,1) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p",(($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6],$aGraphArray[7],$aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _Graph_SetRange_Y ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _Graph_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _Graph_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)),5,1) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6,30,13,2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i],StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)),$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _Graph_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _Graph_Plot_Start(ByRef $aGraphArray,$iX,$iY) ;----- MOVE pen to start point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_MOVE,_Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7], _ $aGraphArray[4]),_Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _Graph_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _Graph_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _Graph_Plot_Line(ByRef $aGraphArray,$iX,$iY) ;----- Draw line from previous point to new point ----- GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_LINE,_Graph_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7], _ $aGraphArray[4]),_Graph_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5])) GUICtrlSetGraphic($aGraphArray[1],$GUI_GR_REFRESH) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow))))) Case "p" Return ($iValue / ($iTotalPixels/ ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Grid ; Description ...: makes X and/or Y grid. ; Syntax.........: _Graph_Grid($graph, $Xlines, $Ylines, $color=0xf0f0f0) ; Parameters ....: $Grap - the array returned from _Graph_Create ; $Xlines - # of grid lines per _Graph_SetRange_X Xticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no X grid ; $Ylines - # of grid lines per _Graph_SetRange_Y Yticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no Y grid ; $color - [optional] RGB value, defining color of grid. Default is a light gray, 0xf0f0f0 ; ======================================================================================= Func _Graph_Grid($graph, $Xticks=1, $Yticks=1, $color=0xf0f0f0) GUICtrlSetGraphic($graph[1], $GUI_GR_COLOR, $color) If $Xticks > 0 Then For $k = $graph[6]+$Xticks to $graph[7] Step $Xticks _Graph_Plot_Start($graph,$k,$graph[8]) ;grade _Graph_Plot_Line($graph,$k,$graph[9]) Next EndIf If $Yticks > 0 Then For $k = $graph[8]+$Yticks to $graph[9] Step $Yticks _Graph_Plot_Start($graph,$graph[6],$k) ;grade _Graph_Plot_Line($graph,$graph[7],$k) Next EndIf GUICtrlSetGraphic($graph[1], $GUI_GR_COLOR,0) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_LineColor ; Description ...: changes color for all future drawed lines up to a new _Graph_LineColor. ; Syntax.........: _Graph_LineColor($graph, $color=0x000000) ; Parameters ....: $Grap - the array returned from _Graph_Create ; $$color - [optional] RGB value, defining color of grid. Default is black, 0x000000 ; ======================================================================================= Func _Graph_LineColor($graph, $color=0x000000) GUICtrlSetGraphic($graph[1], $GUI_GR_COLOR, $color) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Mark ; Description ...: start to put "+" marks at the end of each drawed line. To stop, call it again (see parameter $on) ; Syntax.........: _Graph_Mark($graph,$on=0) ; Parameters ....: $Grap - the array returned from _Graph_Create ; $on - 1 = after this call, all lines will be marked. ; 0 = default = stops to mark ; ==> so, you need to call it with 1 to start the marks and with 0 to stop the marks ; ======================================================================================= Func _Graph_Mark($graph,$on=0) GUICtrlSetGraphic($graph[1], $GUI_GR_HINT, $on) EndFuncAlso, to help, follows a real application where I read a text file and display 2 lines in 2 distinct colors, with marks, etc. (this is a internet server performance checker during the day as users "fells" response time -> there is an AU3 script that from time to time simulates an user access to server and record startup time and browse time). Shown just the graph generation.expandcollapse popupfunc Grafico() ; [url="http://www.autoitscript.com/forum/index.php?showtopic=79412&st=0&gopid=722953"]http://www.autoitscript.com/forum/index....ex.php?showtopic=79412&st=0&gopid=722953[/url]& Local $graph=0 $nomArqLog= FileOpenDialog("Escolha data LOG",@ScriptDir,"Log(LogTemp*.txt)",1) If @error Then Return ;ContinueLoop $file = FileOpen($nomArqLog, 0) If $file = -1 Then MsgBox(0, "Error", "Incapaz de abrir o arquivo") Exit EndIf ;---- cria tela q vai receber o grafico e o proprio grafico, com seus eixos x,y #Region ### START Koda GUI section ### Form=C:\Projeto\PIC\SalaProc3\GrafTempo1.kxf Local $Form1 = GUICreate("GraficoAcesso", 801, 551, 1, 1) ;cria tela p/ exibir o grafico GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $graph = _Graph_Create(30,15,752,510) ;left, top, width, height do grafico ;----- set graph axes ----- _Graph_SetRange_X($graph,0,24,24,1) ;graph name, low, high, number of ticks -> escala X _Graph_SetRange_Y($graph,2,16,14) ;graph name, low, high, number of ticks -> escala Y _Graph_Grid($graph,0.5,0.5) $x=0 While 1 ;lê cada linha do log escolhido e captura os campos hora x temperatura $line = FileReadLine($file) ;$line = FileReadLine($file) If @error = -1 Then ExitLoop $campos=StringSplit($line,";") $x=$x+1 $z= StringSplit($campos[1],":") ; converte hh:mm em hh.fracao ex: 12:30 = 12.5 $px= $Z[1]+($Z[2]/60) $py= $campos[2] If $x = 1 Then _Graph_Plot_Start($graph,$px,$py) ;graph name, x, y -> primeiro ponto _Graph_Plot_Line($graph,$px,$py) ;graph name, x, y -> demais pontos If $campos[3] < 0 Then _Graph_LineColor($graph, 0xff0000 ) ;cor vermelha _Graph_Mark($graph,1) ;faz marquinha _Graph_Plot_Line($graph,$px,$yAnterior) ;linha vertical p/ cima. _Graph_Mark($graph) ;não faz mais marquinhas _Graph_LineColor($graph, 0x000000 ) ;volta cor da linha a preto EndIf $xAnterior= $px $yAnterior= $py Wend FileClose($file) $file = FileOpen($nomArqLog, 0) $x=0 $color=0xf0f000 ;amarelo claro _Graph_LineColor($graph, $color) While 1 ;lê cada linha do log escolhido e captura os campos hora x temperatura $line = FileReadLine($file) ;$line = FileReadLine($file) If @error = -1 Then ExitLoop $campos=StringSplit($line,";") $x=$x+1 $z= StringSplit($campos[1],":") ; converte hh:mm em hh.fracao ex: 12:30 = 12.5 $px= $Z[1]+($Z[2]/60) $py= $campos[4]/2 If $x = 1 Then _Graph_Plot_Start($graph,$px,$py) ;graph name, x, y -> primeiro ponto _Graph_Plot_Line($graph,$px,$py) ;graph name, x, y -> demais pontos Wend FileClose($file) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;, $bt_Sair ExitLoop ; Case $bt_arqLog EndSwitch WEnd GUIDelete($Form1) EndFuncAnd here is real data adquired during a part of the day to be used in the above example00:00;5.2;230;17.7 00:05;3.34;-11;11 00:11;3.76;242.2;17.5 00:17;3.74;203;17.1 00:23;2.9;184.8;13.4 00:29;2.9;177.4;13.6 00:35;2.9;188;17.1 00:41;7.14;202.8;12.7 00:47;2.92;227.4;14.3 00:53;2.9;210.8;13.2 00:59;3.18;155.4;12.9 01:05;3.32;193.6;15.4 01:11;4.02;199.8;15.7 01:17;3.04;194.2;14.2 01:24;8.96;171.8;13.5 01:29;5;258.8;7.2 01:35;2.9;199.2;14.6 01:41;3.18;165.2;16.7 01:47;3.46;202.4;13.8 01:53;3.88;201.6;14.9 01:59;3.6;228.4;13 02:05;3.32;190.6;15.2 02:11;3.18;242.2;12.6 02:17;3.6;214;15.5 02:23;3.32;181.2;16.6 items separated by ";"1st= time of the day2nd=secons browsing the homepage3rd= number of packets received (not shohw in graphics)4rd= seconds to start the browser and to have the 1st page loaded Link to comment Share on other sites More sharing options...
andybiochem Posted October 14, 2009 Author Share Posted October 14, 2009 Added new functions. See OP. Thanks for all the support / ideas!!! - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
BennyBB Posted October 25, 2009 Share Posted October 25, 2009 (edited) Hi andybiochem,When I saw this Funcs ,some months ago I thought, that it could be very useful for me to have some similar Functions, which would make my maths homework So I started to edit your Funcs and I also added some. But time changes, so also our topic in school changed and this work seemed useless to me.Because I think, that they may could help you to make new Funcs or something like this, I post them here. Maybe you find some parts which are useful for you.And sry this were my first udf's in AutoIT and I'm still a noob in coding so sorry if there are many mistakes or if there's something very complicated in the code here's the codeexpandcollapse popup#include-Once #include <GUIConstants.au3> #include <StaticConstants.au3> #cs ------------------------------------------------------------------------------------- Name : Graph-Functions By : Benedikt B. Boesen ; andybiochem : http://www.autoitscript.com/forum/index.php?showtopic=79412&st=0&p=572525&#entry572525 ; Manadar : http://www.autoitscript.com/forum/index.php?showtopic=36254&hl= Date : 6.09.09 Functions: _Graphcreate ; Done _Graphclear ; Done, not tested _Graphdrawcosy ; Done _Graphdrawstraight _Graphdrawgrid ; Done _Graphdrawpoint ; Done _Graphdrawline ; _Graphdrawcircle ; _Graphdrawhalfline ; Done _Graph_Reference_pixel ;;;; Function completely made by andybiochem To do: _Graphdrawhalfline ; Make lines bigger => $GUI_GR_PENSIZE ! _Graphdrawstraight ; _Graphdrawline ; _Graphaddinfos ; Add infos about the geometrical constructions like radius etc. to the graphic _Graphgetpoint ; ?????? Remove _Graph_Reference_Pixel (?) Shorten _Graphdrawhalfline Draw nothing beside the Graphic Make it work for more than one _Graphcreate _Graphdrawpoint in relationship to the graphic Done since 9.9.09 _Graphdrawhalfline _Graphdrawhalfline define graphname function ($xhalflinename,$yhalflinename) and make name larger _Graphdrawpoint make larger X _Graphdrawhalfline ; halbgerade ; geht im moment nur mit positiven m-werten (Steigung) _Graphdrawhalfline Graphenname bei manchen Graphen noch falsch _Graphdrawpoint ; label mit koordinaten und punktnamen -Remove ToolTips - Fixed some problems with _Graphdrawpoint _Graphdrawcircle fertig Date of finishing the udf : soooon :D #ce #Region Functions ; #FUNCTION# ========================================================================== ; Name........: _Graphcreate ; Description.: Creates a graph ; Syntax......: _Graphcreate($gLeft,$gTop,$gRight,$gBottom,$gwidth,$gheight) ; Parameters..: $gLeft - Left end of the graph in Pixel ; $gTop - Top end of the graph in Pixel ; $gwidth - width of graph in pixel ; $height - height of graph in pixel ;return values: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] Right ; [7] Bottom ; [8] x low ; [9] x high ; [10] y low ; [11] y high ;========================================================= Func _Graphcreate($gLeft,$gTop,$gwidth,$gheight) $hwnd = GUICtrlCreateGraphic($gLeft,$gTop,$gwidth,$gheight) GuictrlsetBkColor ($hwnd,0xFFFFFF) GUICtrlSetColor($hwnd,0x000000) $gright = $gwidth+$gLeft $gbottom = $gheight+$gTop Global $grapharray[14] = ["",$hwnd,$gLeft,$gTop,$gwidth,$Gheight,$gright,$gBottom,0,1,0,1,0,1] Global $helparray[8] = ["",0,0,0,0,0,0,0] EndFunc ; #FUNCTION# ======================================================================== ; Name........: _Graphdrawcosy ; Description.: Draws the x and y Axis ; Syntax......: _Graphdrawcosy($hwnd,$xLow,$xHigh,$yLow,$yHigh,$xticks,$yticks,$blabels=1,$iRound=0) ; Parameters..: $hwnd - The control to interact with ; $xLow - Lowest value for the x axis ; $xHigh - Highest value for the x axis ; $yLow - Lowest value for the y axis ; $yHigh - Highest value for the y axis ; $xticks - Number of ticks for the x axis ; $yticks - Number of ticks for the y axis ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ;======================================================= Func _Graphdrawcosy($hwnd,$xLow,$xHigh,$ylow,$yHigh,$xticks,$yticks,$blabels=1,$iRound=0) $grapharray[8]=$xLow $grapharray[9]=$xHigh $GraphArray[10] = $yLow $GraphArray[11] = $yHigh $helparray[1] = $xticks $helparray[2] = $yticks $helparray[3] = $blabels $helparray[4] = $iRound Global $xlowpixel = $grapharray[2] Global $xhighpixel = ($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9] Global $ylowpixel = ($grapharray[5]/(-$grapharray[10]+$grapharray[11]))*(-$grapharray[10]) Global $yhighpixel = $grapharray[3] $0point = Guictrlcreategraphic($grapharray[4]-$xhighpixel+$grapharray[2],$grapharray[5]-$ylowpixel+$grapharray[3]) GUICtrlSetGraphic($0point,$GUI_GR_DOT) GuictrlsetGraphic($0point,$GUI_GR_LINE,$grapharray[4]-$grapharray[9]+$grapharray[2]+20,$grapharray[5]-$grapharray[10]+$grapharray[3]+15) GUICtrlSetGraphic($0point,$GUI_GR_REFRESH) $grapharray[12] = $grapharray[4]-$xhighpixel+$grapharray[2] $grapharray[13] = $grapharray[5]-$ylowpixel+$grapharray[3] ;draw y axis through 0 point $yaxis = GuictrlcreateGraphic($grapharray[4]-$xhighpixel+$grapharray[2],$grapharray[5]+$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel-2,$grapharray[5]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4]-$xhighpixel-2,$grapharray[3]-$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel-1,$grapharray[5]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4]-$xhighpixel-1,$grapharray[3]-$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel,$grapharray[5]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4]-$xhighpixel,$grapharray[3]-$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel+1,$grapharray[5]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4]-$xhighpixel+1,$grapharray[3]-$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel+2,$grapharray[5]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4]-$xhighpixel+2,$grapharray[3]-$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) ;draw x axis through 0 point $xaxis = GuictrlcreateGraphic($grapharray[4]-$xhighpixel+$grapharray[2],$grapharray[5]-$ylowpixel+$grapharray[3]) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2]-$grapharray[2],$grapharray[5]-$ylowpixel-2) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$grapharray[5]-$ylowpixel-2) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2]-$grapharray[2],$grapharray[5]-$ylowpixel-1) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$grapharray[5]-$ylowpixel-1) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2]-$grapharray[2],$grapharray[5]-$ylowpixel) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$grapharray[5]-$ylowpixel) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2]-$grapharray[2],$grapharray[5]-$ylowpixel+1) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$grapharray[5]-$ylowpixel+1) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2]-$grapharray[2],$grapharray[5]-$ylowpixel+2) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$grapharray[5]-$ylowpixel+2) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) ;----- create new ticks ----- Dim $ahTicksX[$xticks] For $i = 2 To $xticks ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("",(($i - 1) * ($grapharray[4] / $xTicks)) + $grapharray[2], _ $grapharray[5]-$ylowpixel+$grapharray[3],1,5) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ---- Dim $ahTicksLabelsX[$xTicks] For $i = 1 to (UBound($XTicks) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- Dim $ahTicksLabelsX[$xTicks] For $i = 2 To $XTicks ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($GraphArray[2] + (($GraphArray[4] / $XTicks) * ($i - 1))) - (($GraphArray[4] / $XTicks) / 2)+5, _ $grapharray[5]-$ylowpixel+$grapharray[3]+10,$GraphArray[4] / $XTicks,13,1) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 2 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p",(($i - 1) * ($GraphArray[4] / $XTicks)), _ $GraphArray[8],$GraphArray[9],$GraphArray[4]))) Next EndIf ;----- create new ticks ----- Dim $ahTicksY[$YTicks] For $i = 2 To $YTicks ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("",$grapharray[4]-$xhighpixel-5+$grapharray[2], _ ($GraphArray[3] + $GraphArray[5]) - (($GraphArray[5] / $YTicks) * ($i - 1)),5,1) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetState(-1,$GUI_DISABLE) Next ;----- delete any existing labels ----- Dim $ahTicksLabelsY[$YTicks] For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 2 To $YTicks ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("",$grapharray[4]-$xhighpixel-10, _ ($GraphArray[3] + $GraphArray[5]) - (($GraphArray[5] / $YTicks) * ($i - 1)),20,13,2) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 2 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i],StringFormat("%." & $iRound & "f",_Graph_Reference_Pixel("p", _ (($i - 1) * ($GraphArray[5] / $YTicks)),$GraphArray[10],$GraphArray[11],$GraphArray[5]))) Next EndIf EndFunc ; This is just the beginning of the Func, i was too lazy to finish it ;) #cs ; #FUNCTION# ============================================================================ ; Name...........: _Graphdrawstraight ; Description....: Draws a straight line trough 2 points ; Syntax.........: _Graphdrawstraight($hwnd,$x1,$y1,$x2,$y2,$color=0xFFFFFF) ; Parameters.....: $hwnd - The control to interact with ; $x1 - The x coordinate of the first point ; $y1 - The y coordinate of the first point ; $x2 - The x coordinate of the second point ; $y2 - The y coordinate of the second point ; $color - The color, the line schould be ;======================================================================================= Func _Graphdrawstraight($hwnd,$x1,$y1,$x2,$y2,$color=0xFFFFFF) $m = ($y2-$y1)/($x2-$x1) ;Steigung $b = -$m*$x1+$y1 ;y- Achsenabschnitt $grapharray[12] =$grapharray[4]-$xhighpixel+$grapharray[2] ; 0point x $grapharray[13] =$grapharray[5]-$ylowpixel+$grapharray[3] ; 0point y #cs $ylinksunten = ($m*$grapharray[8]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11])) $ylinksunten1 = ($ylinksunten/$m-$b) $yrechtsoben = ($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11])) $xrechtsoben = ($m*$grapharray[9]+$b)*($grapharray[4]/(-$grapharray[8]+$grapharray[9])) $xrechtsoben1 = $xrechtsoben/$m-$b $x1pixel = ($grapharray[12]+($grapharray[4]/((-$grapharray[8])+$grapharray[9])*$x1))-$grapharray[2] $y1pixel = ($grapharray[13]-($grapharray[5]/((-$grapharray[10])+$grapharray[11])*$y1))-$grapharray[3] $x2pixel = ($grapharray[12]+($grapharray[4]/((-$grapharray[8])+$grapharray[9])*$x2))-$grapharray[2] $y2pixel = ($grapharray[13]-($grapharray[5]/((-$grapharray[10])+$grapharray[11])*$y2))-$grapharray[3] Guictrlsetgraphic ($grapharray[1],$GUI_GR_DOT,$x1pixel,$y1pixel) Guictrlsetgraphic ($grapharray[1],$GUI_GR_DOT,$x2pixel,$y2pixel) Guictrlsetgraphic ($grapharray[1],$GUI_GR_REFRESH) Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE,$x1pixel,$y1pixel) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$x2pixel,$y2pixel) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[2],($m*$grapharray[8]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Guictrlsetgraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Guictrlsetgraphic($grapharray[1],$GUI_GR_REFRESH) If $m*$grapharray[8]+$b <= $grapharray[10] Then If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,($ylowpixel-$ylinksunten)/$m-$b/$m,$grapharray[5]) ;;;;;; GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[4],($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Else GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,($ylowpixel-$ylinksunten)/$m-$b/$m,$grapharray[5]) ;;;;;; Guictrlsetgraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[4]-(0/$m-$b/$m),0) EndIf Else If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,0,($grapharray[5]-$ylowpixel)-$ylinksunten) ;;;;; GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[4],($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Else GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,0,($grapharray[5]-$ylowpixel)-$ylinksunten) ;;;;; Guictrlsetgraphic ($grapharray[1],$GUI_GR_LINE,0/$m-$b/$m,0) EndIf EndIf Guictrlsetgraphic ($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_DOT,$grapharray[4]/(-$grapharray[8]+$grapharray[9])*$grapharray[8],($grapharray[5]-$ylowpixel)-$ylinksunten) Guictrlsetgraphic ($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_DOT,0,($grapharray[5]-$ylowpixel)-$ylinksunten) Guictrlsetgraphic ($grapharray[1],$GUI_GR_REFRESH) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_DOT,(($grapharray[5]-$ylowpixel)-$ylinksunten-$grapharray[5])/$m-$b,$grapharray[5]) #ce #cs _Graphdrawpoint($hwnd,"A",$x1,$y1) _Graphdrawpoint($hwnd,"B",$x2,$y2) Dim $h = 0 If $m*$grapharray[8]+$b > $grapharray[11] and If $m*$grapharray[9]+$b < $grapharray[10] Then $h = 1 If $m*$grapharray[8]+$b > $grapharray[11] ................ #ce EndFunc #ce ; #FUNCTION# ================================================================================ ; Name.........: _Graphdrawgrid ; Description..: Draws the grid into the graphic ; Syntax.......: _Graphdrawgrid($hwnd,$xLines=1,$ylines=1,$color=0xf0f0f0 ; Parameters...: $hwnd - The cpntrol to interact with ; $xlines - # of grid lines per Xticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no X grid ; $ylines - # of grid lines per Yticks -> 1= one line per tick, 2= 1 line at each 2 ticks..., ; 0.5= 2 lines per tic. Default=1, and 0=no Y grid ; $color - [optional] RGB value, defining color of grid. Default is a light gray, 0x000000 ;=========================================================================================== Func _Graphdrawgrid($hwnd,$xLines=1,$yLines=1,$color=0x000000) $helparray[5] =$xLines $helparray[6] =$yLines $helparray[7] =$color GUICtrlSetGraphic($grapharray[1], $GUI_GR_COLOR, $color) $b = $xLines If $Xlines > 0 Then For $k = $grapharray[8] to $grapharray[9]-1 Step $Xlines $i = 0 $a = (($i+$b)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) Guictrlsetgraphic($grapharray[1],$GUI_GR_MOVE,$a,$grapharray[5]) ;grade Guictrlsetgraphic($grapharray[1],$GUI_GR_LINE,$a,0) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) $b = $b+$xLines Next EndIf $c = $ylines If $Ylines > 0 Then For $k = $grapharray[10] to $grapharray[11]-1 Step $Ylines $i = 0 $a = ($i+$c)*($grapharray[5]/(-$grapharray[10]+$grapharray[11])) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) Guictrlsetgraphic($grapharray[1],$GUI_GR_MOVE,0,$a) ;grade GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],$a) GUICtrlSetGraphic($grapharray[1],$GUI_GR_REFRESH) $c = $c+$ylines Next EndIf GUICtrlSetGraphic($grapharray[1], $GUI_GR_COLOR,$color) EndFunc ; #FUNCTION# =============================================================================== ; Name.........: _Graphdrawpoint ; Description..: Draws a point with name and cooridnates ; Syntax.......: _Graphdrawpoint($hwnd,$name,$x,$y,$color=0x000000) ; Parameters...: $hwnd - The control to interact With ; $name - The point's name ; $x - x position ; $y - y position ; $color - the point's color, default is 0x000000 ;============================================================================================== Func _Graphdrawpoint($hwnd,$name,$x,$y,$color=0x000000) If $x <> 0 and $y <> 0 Then $xcross = GUICtrlCreateLabel("X",$x*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-5, _ ($grapharray[11]-$y)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+9) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($xcross,$color) guictrlsetfont (-1,14) $text = GuictrlcreateLabel ($name & "(" & Round($x,2) & "|" & Round($y,2) & ")",$x*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]+ 10, _ ($grapharray[11]-$y)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+15,100,30) GUICtrlSetBkColor($text,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($text,0x000000) guictrlsetfont ($text,12) ElseIf $x = 0 and $y <> 0 Then $xcross = GUICtrlCreateLabel("X",$grapharray[12]-5, _ ($grapharray[11]-$y)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+9) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($xcross,$color) guictrlsetfont (-1,14) $text = GuictrlcreateLabel ($name & "(" & Round($x,2) & "|" & Round($y,2) & ")",$grapharray[12]-5, _ ($grapharray[11]-$y)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+15,100,30) GUICtrlSetBkColor($text,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($text,0x000000) guictrlsetfont ($text,12) ElseIf $x <> 0 and $y = 0 Then $xcross = GUICtrlCreateLabel("X",$x*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-5, _ $grapharray[13]-$grapharray[3]+9) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($xcross,$color) guictrlsetfont (-1,14) $text = GuictrlcreateLabel ($name & "(" & Round($x,2) & "|" & Round($y,2) & ")",$x*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-8, _ $grapharray[13]-$grapharray[3]-4,100,30) GUICtrlSetBkColor($text,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($text,0x000000) guictrlsetfont ($text,12) ElseIf $x=0 and $y=0 Then $xcross = GUICtrlCreateLabel("X",$grapharray[12]-5, _ $grapharray[13]-$grapharray[3]+9) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($xcross,$color) guictrlsetfont (-1,14) $text = GuictrlcreateLabel ($name & "(" & Round($x,2) & "|" & Round($y,2) & ")",$grapharray[12]+8, _ $grapharray[13]-$grapharray[3]-4,100,30) GUICtrlSetBkColor($text,$GUI_BKCOLOR_TRANSPARENT) Guictrlsetcolor ($text,0x000000) guictrlsetfont ($text,12) EndIf EndFunc ; #FUNCTION# ================================================================================ ; Name.........: _Graphdrawhalfline ; Description..: Draws a halfline. It starts from 1 point and goes through another one ; Syntax.......: _Graphdrawhalfline($hwnd,$name,$xstart,$ystart,$x2,$y2,$color=0x000000) ; Parameters...: $hwnd - The control to interact with ; $name - The graph's name ; $xstart - The start-point's x coordinate ; $ystart - The start-point's y coordinate ; $x2 - The x coordinate of the point to go through ; $y2 - The y coordinate of the point to go through ; $color - The color the half line schould be ;=========================================================================================== Func _Graphdrawhalfline($hwnd,$name,$xstart,$ystart,$x2,$y2,$color=0x000000) If $name = "" Then $name = "g" EndIf $m = ($y2-$ystart)/($x2-$xstart) $b = -$m*$xstart+$ystart _Graphdrawpoint($hwnd,"A",$xstart,$ystart,0x000000) _Graphdrawpoint($hwnd,"B",$x2,$y2,0x000000) If $xstart < $x2 Then ;fertig If $ystart < $y2 Then ;fertig If $ystart=0 and $xstart <> 0 Then GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),$grapharray[5]-$ylowpixel) ; stimmt .....! GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b < $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-($m*$grapharray[9]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt 1000% :D:D EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ; stimmt EndIf Elseif $xstart = 0 and $ystart <> 0 Then GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel,($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;;;;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-($m*$grapharray[9]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ;stimmt EndIf ElseIf $xstart=0 and $ystart = 0 Then Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],$grapharray[13]-$grapharray[3]);stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-($m*$grapharray[9]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11])));stimmt EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ;stimmt EndIf ElseIf $xstart <> 0 and $ystart <> 0 Then GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-($m*$grapharray[9]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) EndIf EndIf ElseIf $ystart > $y2 Then ;fertig If $ystart=0 and $xstart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),$grapharray[5]-$ylowpixel) ; stimmt .....! GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-($m*$grapharray[9]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt 1000% :D:D EndIf If $m*$grapharray[9]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ; stimmt EndIf Elseif $xstart = 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel,($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;;;;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[13]-$grapharray[3]-(($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) ;stimmt EndIf If $m*$grapharray[9]+$b <= $grapharray[10] Then ;fertig GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ;stimmt EndIf ElseIf $xstart=0 and $ystart = 0 Then ;fertig Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],$grapharray[13]-$grapharray[3]);stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[13]-$grapharray[3]-(($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) EndIf If $m*$grapharray[9]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ;stimmt EndIf ElseIf $xstart <> 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[13]-$grapharray[3]-(($m*$grapharray[9]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) EndIf If $m*$grapharray[9]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[4]-($grapharray[4]/(-$grapharray[8]+$grapharray[9]))*$grapharray[9])+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) EndIf EndIf Elseif $ystart = $y2 Then ;fertig Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE, $xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Guictrlsetgraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[4],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) EndIf Elseif $xstart = $x2 Then ;fertig If $ystart < $y2 Then ;fertig If $xstart = 0 Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ; fertig GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[12]-$grapharray[2],0) ; fertig Elseif $xstart <> 0 Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),0) EndIf ElseIf $ystart > $y2 Then ;fertig If $xstart = 0 Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ; fertig GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$grapharray[12]-$grapharray[2],$grapharray[5]) ; fertig Elseif $xstart <> 0 Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),$grapharray[5]) EndIf EndIf ElseIf $xstart > $x2 Then ;fertig If $ystart < $y2 Then ;fertig If $ystart=0 and $xstart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),$grapharray[5]-$ylowpixel) ; stimmt .....! GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[8]+$b < $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-($m*$grapharray[8]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt 1000% :D:D EndIf If $m*$grapharray[8]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[12]-$grapharray[2])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ; stimmt EndIf Elseif $xstart = 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel,($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;;;;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-($m*$grapharray[8]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,(($grapharray[12]-$grapharray[2])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ;stimmt EndIf ElseIf $xstart=0 and $ystart = 0 Then ;fertig Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],$grapharray[13]-$grapharray[3]);stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-($m*$grapharray[8]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11])));stimmt EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,(($grapharray[12]-$grapharray[2])+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) ;stimmt EndIf ElseIf $xstart <> 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[9]+$b <= $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-($m*$grapharray[8]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) EndIf If $m*$grapharray[9]+$b > $grapharray[11] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[12]-$grapharray[2]+(($grapharray[11]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),0) EndIf EndIf ElseIf $ystart > $y2 Then ;fertig If $ystart=0 and $xstart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+($grapharray[4]-$xhighpixel),$grapharray[5]-$ylowpixel) ; stimmt .....! GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[8]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GuiCtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-($m*$grapharray[8]+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt 1000% :D:D EndIf If $m*$grapharray[8]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,($grapharray[12]-$grapharray[2])+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ; stimmt EndIf Elseif $xstart = 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$grapharray[4]-$xhighpixel,($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;;;;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[8]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[13]-$grapharray[3]-(($m*$grapharray[8]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) ;stimmt EndIf If $m*$grapharray[8]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[12]-$grapharray[2]+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ;stimmt EndIf ElseIf $xstart=0 and $ystart = 0 Then ;fertig Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],$grapharray[13]-$grapharray[3]);stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[8]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[13]-$grapharray[3]-(($m*$grapharray[8]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) EndIf If $m*$grapharray[8]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[12]-$grapharray[2]+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) ;stimmt EndIf ElseIf $xstart <> 0 and $ystart <> 0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_MOVE,$xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) ;stimmt GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) If $m*$grapharray[8]+$b > $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,0,($grapharray[13]-$grapharray[3]-(($m*$grapharray[8]+$b)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))))) EndIf If $m*$grapharray[8]+$b <= $grapharray[10] Then GUICtrlSetGraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic($grapharray[1],$GUI_GR_LINE,$grapharray[12]-$grapharray[2]+(($grapharray[10]/$m-$b/$m)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))),$grapharray[5]) EndIf EndIf ElseIf $ystart = $y2 Then ;fertig Guictrlsetgraphic ($grapharray[1],$GUI_GR_MOVE, $xstart*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2],($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) Guictrlsetgraphic ($grapharray[1],$GUI_GR_COLOR,$color) GUICtrlSetGraphic ($grapharray[1],$GUI_GR_LINE,0,($grapharray[11]-$ystart)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))) EndIf EndIf Guictrlsetgraphic ($grapharray[1],$GUI_GR_REFRESH) #Region Give the Graph a name ; not Ready i think !! If $xstart < $x2 Then If $x2-$xstart > 2.0001 and $x2-$xstart <= 3 Then $help1 = Random($xstart,$x2) Elseif $x2-$xstart > 3 Then $help1 = Random($xstart+1,$x2-1) Elseif $x2-$xstart < 2 Then $help1 = Random($xstart-1,$x2+6) EndIf Elseif $xstart > $x2 Then If $x2-$xstart > -2.0001 and $x2-$xstart <= -3 Then $help1 = Random($x2,$xstart) Elseif $x2-$xstart > -3 Then $help1 = Random($x2-1,$xstart+1) Elseif $x2-$xstart < -2 Then $help1 = Random($x2+6,$xstart-1) EndIf EndIf $xhalflinename = $help1*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2] $yhalflinename = ($grapharray[11]-($m*$help1+$b))*($grapharray[5]/(-$grapharray[10]+$grapharray[11])) GuictrlcreateLabel ($name,$xhalflinename,$yhalflinename-5,30,30) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1,$color) GUICtrlSetFont(-1,16) #EndRegion EndFunc ; #FUNCTION# ============================================================================== ; Name...........: _Graphdrawline ; Description....: Draws a line between two points ; Syntax.........: _Graphdrawline($hwnd,$x1,$y1,$x2,$y2,$color=0x000000) ; Parameters.....: $hwnd - The control Id to interact With ; $x1 - x coordinate of the first point ; $y1 - y coordinate of the first point ; $x2 - x coordinate of the second point ; $y2 - y coordinate of the second point ; $color - Color the line should be ;======================================================================================== Func _Graphdrawline($hwnd,$x1,$y1,$x2,$y2,$color=0x000000) _Graphdrawpoint ($hwnd,"A",$x1,$y1,0x000000) _Graphdrawpoint ($hwnd,"b",$x2,$y2,0x000000) If $x1 = 0 Then Guictrlsetgraphic ($hwnd,$GUI_GR_MOVE,$grapharray[12]-$grapharray[2],$y1*$grapharray) EndIf EndFunc ; #FUNCTION# ============================================================================== ; ; ; ;========================================================================================= Func _Graphclear($hwnd) GUICtrlDelete ($hwnd) _Graphcreate($grapharray[2],$grapharray[3],$grapharray[6],$grapharray[7],$grapharray[4],$grapharray[5] _Graphdrawcosy($grapharray[1],$grapharray[8],$grapharray[9],$grapharray[10],$grapharray[11],$helparray[1],$helparray[2],$helparray[3],$helparray[4]) _Graphdrawgrid($grapharray[1],$helparray[5],$helparray[6],$helparray[7]) EndFunc ; #FUNCTION# ============================================================================== ;========================================================================================== Func _Graphdrawcircle($hwnd,$middlex,$middley,$radius,$color=0x000000) _Graphdrawpoint($hwnd,"M",$middlex,$middley,$color) $pixelradius = $radius*($grapharray[4]/(-$grapharray[8]+$grapharray[9])) IF $middlex=0 and $middley=0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_ELLIPSE,$grapharray[12]+((-$middlex-$radius)*($grapharray[4]/(-$grapharray[8]+$grapharray[9])))-$grapharray[2], _ $grapharray[13]+(($middley-$radius)*($grapharray[5]/(-$grapharray[10]+$grapharray[11])))-$grapharray[3],$pixelradius*2,$pixelradius*2) ElseIf $middlex=0 and $middley<>0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_ELLIPSE,$grapharray[12]+((-$middlex-$radius)*($grapharray[4]/(-$grapharray[8]+$grapharray[9])))-$grapharray[2], _ (-$middley-$radius)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+$grapharray[13]-$grapharray[3],$pixelradius*2,$pixelradius*2) ElseIf $middlex<>0 and $middley=0 Then GUICtrlSetGraphic($grapharray[1],$GUI_GR_ELLIPSE,($middlex-$radius)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2], _ $grapharray[13]+(($middley-$radius)*($grapharray[5]/(-$grapharray[10]+$grapharray[11])))-$grapharray[3],$pixelradius*2,$pixelradius*2) ElseIf $middlex<> 0 and $middley<>0 Then ;fertig GUICtrlSetGraphic($grapharray[1],$GUI_GR_ELLIPSE,($middlex-$radius)*($grapharray[4]/(-$grapharray[8]+$grapharray[9]))+$grapharray[12]-$grapharray[2], _ (-$middley-$radius)*($grapharray[5]/(-$grapharray[10]+$grapharray[11]))+$grapharray[13]-$grapharray[3],$pixelradius*2,$pixelradius*2) EndIf EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _Graph_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow))))) Case "p" Return ($iValue / ($iTotalPixels/ ($iHigh - $iLow))) + $iLow EndSwitch EndFunc #EndRegionYou can use it for things like thisM.f.G. BennyBBEdit 14. Dec : ok still the old code but I began to work on this again... but it's proceeding rather slow Edited December 14, 2009 by BennyBB Link to comment Share on other sites More sharing options...
Qwerty212 Posted October 24, 2010 Share Posted October 24, 2010 Thanks for the udf.I'm trying to add a graph to my GUI and I don't know the difference between this UDF and GDI+ one.The case is that I want to fill something like:with the values of a variable that I change manually with something like guictrlsetdata($variable,10)Can I draw a line between every point with this version or I'm going to need the GDI+ one?It would be great to see the evolution of a measuring program.And when I've more than 10 or 20 result can the first ones be moved outside the graph?Because there is going to be a moment where the points will not fit inside the graph (I've a poor english level, maybe _Graph_Plot_Start is what I'm asking for?)Thanks for your contribution. Link to comment Share on other sites More sharing options...
taietel Posted October 24, 2010 Share Posted October 24, 2010 adolfito121, take a look at this post of andybiochem. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Qwerty212 Posted October 24, 2010 Share Posted October 24, 2010 (edited) adolfito121, take a look at this post of andybiochem. Thanks EDIT: I don't know what I'm doing wrong I've taked the example from andybiochem and tried to adapt to my script like that: Global $aData = GUICTRLREAD($input7) Global $i = 1 Global $gGraph = _Graph_Create(30, $altogui4 - 320, $anchogui4 - 250, 280) _Graph_Set_Color($gGraph, 0x000000) _Graph_SetRange_X($gGraph, 1, 20, 20) _Graph_SetRange_Y($gGraph, $valorinput2, $valorinput1, 10);The minimun and max values are going to be variables from an user input at the beggining of the program Func _Redraw() GUISetState(@SW_LOCK) _Graph_Clear($gGraph) _Graph_SetGrid_X($gGraph, 5, 0x468c2f) _Graph_SetGrid_Y($gGraph, 10, 0x468c2f) _Graph_Set_Color($gGraph, 0x000000) _Graph_Plot_Start($gGraph, 1, $gGraph[1]) _Graph_Plot_Line($gGraph, $aData, $i) _Graph_Plot_Point($gGraph, $aData, $i) _Graph_Refresh($gGraph) $i = $i + 1 GUISetState(@SW_UNLOCK) EndFunc ;==>_Redraw I've tried to adapt taking out the random part of this example: expandcollapse popup#include <GUIConstantsEx.au3> GUICreate("", 586, 314, -1, -1, -1, 0x2000000) Global $aData[101] Global $gGraph = _Graph_Create(50, 18, 513, 254) _Graph_SetRange_X($gGraph, 1, 100, 0) _Graph_SetRange_Y($gGraph, 0, 100, 10) _Redraw() GUISetState() Do Sleep(50) _Randomise() _Redraw() Until GUIGetMsg() = -3 Func _Randomise() For $i = 1 To 99 $aData[$i] = $aData[$i + 1] Next $aData[100] = Random(0, 100) EndFunc ;==>_Randomise Func _Redraw() GUISetState(@SW_LOCK) _Graph_Clear($gGraph) _Graph_SetGrid_X($gGraph, 5, 0x468c2f) _Graph_SetGrid_Y($gGraph, 10, 0x468c2f) _Graph_Set_Color($gGraph, 0xF9F32B) _Graph_Plot_Start($gGraph, 1, $gGraph[1]) For $i = 1 To 100 _Graph_Plot_Line($gGraph, $i, $aData[$i]) _Graph_Plot_Point($gGraph, $i, $aData[$i]) Next _Graph_Refresh($gGraph) GUISetState(@SW_UNLOCK) EndFunc ;==>_Redraw But trying to make the value $aData the value of a variable: $coord1 = PixelSearch($size[0], $size[1] + $mitad, $size[0] + $size[2], $size[1] + $mitad, $color, $algoritmo * 3);~a pixelsearch with its coordenates If Not @error Then ; $medida = ($size[2] - $coord1[0]) / 10;~I just need the distance between the starting coordenates of the searching area of pixelsearch and the point where it found the pixel searched StringFormat("%#.2f", $medida) GUICtrlSetData($input7, $medida);~I tell the script to write on an only read inputbox the value given for that pixel search (a distance between two points, basically) ;~Finally I try to send the data to the graph _Redraw() When I'm doing the pixelsearch the graph flashes and it turns transparent and it doen't shows any point or neither any line. Do I'm very far of my porpouse? Thanks again Edited October 24, 2010 by adolfito121 Link to comment Share on other sites More sharing options...
taietel Posted October 24, 2010 Share Posted October 24, 2010 (edited) If you want to draw a value from the input, modify like this Func _Randomise() For $i = 1 To 99 $aData[$i] = $aData[$i + 1] Next $aData[100] = GuiCtrlRead($input7) EndFunc ;==>_Randomise Edited October 24, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Qwerty212 Posted October 24, 2010 Share Posted October 24, 2010 (edited) If you want to draw a value from the input, modify like this Func _Randomise() For $i = 1 To 99 $aData[$i] = $aData[$i + 1] Next $aData[100] = GuiCtrlRead($input7) EndFunc ;==>_Randomise mersi taietel. $i value is "how many points are going to be drawed before starting moving the graphs to the side"? I've two gui (one transparent to limit the pixelsearch area and the main one where grapmust be drawed.) At the starting of the script the graphs is showed on the maingui, but when is going to draw the firs value the graph remains on it's place and the little gui shows a line. This is how it looks at the beggining and this is what it does when it has to draw the first redraw the graph I'm sure that it has to be my fault (my wife tells me everytime, on everything, so that time is not going to be different). I call the _redraw and the _randomize functions with a button: $coord1 = PixelSearch($size[0], $size[1] + $mitad, $size[0] + $size[2], $size[1] + $mitad, $color, $algoritmo * 3);~a pixelsearch with its coordenates If Not @error Then ; $medida = ($size[2] - $coord1[0]) / 10;~I just need the distance between the starting coordenates of the searching area of pixelsearch and the point where it found the pixel searched StringFormat("%#.2f", $medida) GUICtrlSetData($input7, $medida);~I tell the script to write on an only read inputbox the value given for that pixel search (a distance between two points, basically) ;~Finally I try to send the data to the graph _Randomise() _Redraw() The transparent gui is created with this parameter: $Guipeque = GUICreate("minigui", $posicionxguipeque1, $posicionyguipeque1, $altoguipeque1, $anchoguipeque1, $WS_POPUPWINDOW, $WS_EX_LAYERED + $GUI_WS_EX_PARENTDRAG, WinGetHandle(AutoItWinGetTitle())) WinSetOnTop($Guipeque, "minigui", 1);~to make the gui over the main gui, because is going to be a searching area limitator GUISetBkColor(0xABCDEF) _WinAPI_SetLayeredWindowAttributes($Guipeque, 0xABCDEF, 255) Any ideas of what I'm doing wrong? Thanks again Edited October 24, 2010 by adolfito121 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now