Sign in to follow this  
Followers 0
nikosliapis

graph from array

4 posts in this topic

Hello everybody.

I need a function that will produce a graph from a 2D array.

I believe that i am doing pretty well with simple scripts but when i must create a GUI window i suck, therefore i ask

for your help.

I would really appreciate any help provided.


Coding can be fun when you do it your own.

Share this post


Link to post
Share on other sites



nikosliapis,

You may want to look at this topic.

The "Search" button is at the top on the right, by the way. ;)

M23


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

Spoiler

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

 

Share this post


Link to post
Share on other sites

I would like to apologise if i caused you any disconvinience.

I have allready checked this UDF but i couldn't understand how to import my data so that the graph will be created.

Thanks for your time.


Coding can be fun when you do it your own.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Simple example.

#Include <GDIPlus.au3>
#Include <GUIConstantsEx.au3>
#Include <Math.au3>
#Include <WinAPI.au3>

Opt('MustDeclareVars', 1)

Dim $aPoints[300][2]

For $i = 0 To UBound($aPoints) - 1
    $aPoints[$i][0] = ($i - 150) / 1.7
    $aPoints[$i][1] = 20 * Sin($aPoints[$i][0] / 20) * Sin($aPoints[$i][0] / 2)
Next

_ViewGraph($aPoints)

Func _ViewGraph($aPoints)

    Local $hForm, $Pic, $hPic
    Local $Scale, $Xi, $Yi, $Xp, $Yp, $XOffset, $YOffset, $Xmin = $aPoints[0][0], $Ymin = $aPoints[0][1], $Xmax = $Xmin, $Ymax = $Ymin
    Local $hBitmap, $hObj, $hGraphic, $hImage, $hBrush, $hPen

    For $i = 1 To UBound($aPoints) - 1
        If $aPoints[$i][0] < $Xmin Then
            $Xmin = $aPoints[$i][0]
        Else
            If $aPoints[$i][0] > $Xmax Then
                $Xmax = $aPoints[$i][0]
            EndIf
        EndIf
        If $aPoints[$i][1] < $Ymin Then
            $Ymin = $aPoints[$i][1]
        Else
            If $aPoints[$i][1] > $Ymax Then
                $Ymax = $aPoints[$i][1]
            EndIf
        EndIf
    Next

    $Scale = 600 / _Max($Xmax - $Xmin, $Ymax - $Ymin)
    $XOffset = Floor(($Xmin + $Xmax) * $Scale / 2)
    $YOffset = Floor(($Ymin + $Ymax) * $Scale / 2)

    _GDIPlus_Startup()
    $hBitmap = _WinAPI_CreateBitmap(601, 601, 1, 32)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    _WinAPI_DeleteObject($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hPen = _GDIPlus_PenCreate(0xFFFF0000)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, 601, 601, $hBrush)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    If Abs($XOffset) <= 300 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, 300 - $XOffset, 0, 300 - $XOffset, 601, $hPen)
    EndIf
    If Abs($YOffset) <= 300 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, 0, 300 + $YOffset, 601, 300 + $YOffset, $hPen)
    EndIf
    _GDIPlus_PenDispose($hPen)
    $hPen = _GDIPlus_PenCreate(0xFF000000)
    For $i = 0 To UBound($aPoints) - 1
        $Xi = 300 - $XOffset + $Scale * $aPoints[$i][0]
        $Yi = 300 + $YOffset - $Scale * $aPoints[$i][1]
        If $i Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $Xp, $Yp, $Xi, $Yi, $hPen)
        EndIf
        $Xp = $Xi
        $Yp = $Yi
    Next
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()

    $hForm = GUICreate('My Graph', 601, 601)
    $Pic = GUICtrlCreatePic('', 0, 0, 601, 601)
    $hPic = GUICtrlGetHandle(-1)

    _WinAPI_DeleteObject(_SendMessage($hPic, 0x0172, 0, $hBitmap))
    $hObj = _SendMessage($hPic, 0x0173)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf

    GUISetState(@SW_SHOW, $hForm)

    Do
    Until GUIGetMsg() = -3

    GUIDelete($hForm)

EndFunc   ;==>_ViewGraph
Edited by Yashied

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0