Jump to content
Sign in to follow this  
darzanmihai

Need some help to create a chart from an array

Recommended Posts

darzanmihai

How could I create a chart (with bars) into a Gui from a 2D array .

Could anyone help me with this matter?

I have tryed the GUICtrlCreateGraphic() function but I can't seem to understand It!

I would really apreciate a script example!


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
JFee

Look at GUICtrlSetGraphic in the helpfile

That is how you do things with a Graphic control, so you can create different rectangles for your bars with heights according to the data from your array


Regards,Josh

Share this post


Link to post
Share on other sites
darzanmihai

Look at GUICtrlSetGraphic in the helpfile

That is how you do things with a Graphic control, so you can create different rectangles for your bars with heights according to the data from your array

I know that function, but I do not understand it...I need an example for what I am trying to do....


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
JFee

From the helpfile:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Global $MAXGr = 6, $del, $child
Global $a[$MAXGr + 1]; 0 and $MAXGr entries not used to allow GUICtrlDelete result

Example()

Func Example()
    Local $msg, $inc, $i, $del1

    GUICreate("My Main", -1, -1, 100, 100)
    $del1 = GUICtrlCreateButton("Delete", 50, 200, 50)
    GUISetState()
    CreateChild()

    $i = 1
    $inc = 1
;$i=5; uncomment to delete starting from last define Graphic control
;$inc=-1

    Do
        $msg = GUIGetMsg()
        If $msg = $del1 Then $i = Del($inc)

        If $msg = $del Then
            GUICtrlDelete($a[$i])
            $i = $i + $inc
            If $i < 0 Or $i > $MAXGr Then Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc  ;==>Example

Func Del($iInc)
    GUIDelete($child)
    CreateChild()
    If $iInc = -1 Then Return 5
    Return 1
EndFunc  ;==>Del

Func CreateChild()
    $child = GUICreate("My Draw")
    $del = GUICtrlCreateButton("Delete", 50, 165, 50)

    $a[1] = GUICtrlCreateGraphic(20, 50, 100, 100)
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlSetColor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90)

    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 100, 100, 50, 80)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xc0c0ff)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 350, 200, 50, 80)
    GUICtrlCreateLabel("label", 65, 100, 30)
    GUICtrlSetColor(-1, 0xff)

    $a[2] = GUICtrlCreateGraphic(220, 10, 100, 100)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90)

    $a[3] = GUICtrlCreateGraphic(220, 110, 100, 100)
    GUICtrlSetBkColor(-1, 0xf08080)
    GUICtrlSetColor(-1, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 80, 80)

    $a[4] = GUICtrlCreateGraphic(20, 200, 80, 80)
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1)

    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 30, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 70, 70)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 50)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 10)

    $a[5] = GUICtrlCreateGraphic(150, 10, 50, 50)
    GUICtrlSetBkColor(-1, 0xa0ffa0)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20) ; start point
; it is better to draw line and after point
; to avoid to switch color at each drawing
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 30)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 40)

    $a[6] = GUICtrlCreateGraphic(110, 260, 230, 130)
    GUICtrlSetColor(-1, 0) ; to display a black border line
    GUICtrlSetBkColor(-1, 0xc0c0ff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 3) ; to display control lines and end points

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff); fill in blue
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 120, 20) ; start point
    GUICtrlSetGraphic(-1, $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100)
    GUICtrlSetGraphic(-1, $GUI_GR_BEZIER + $GUI_GR_CLOSE, 100, 40, 40, 100, 40, 20)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 60, 30) ; start point

    GUISetState()
EndFunc  ;==>CreateChild

Regards,Josh

Share this post


Link to post
Share on other sites
darzanmihai

From the helpfile:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Global $MAXGr = 6, $del, $child
Global $a[$MAXGr + 1]; 0 and $MAXGr entries not used to allow GUICtrlDelete result

Example()

Func Example()
    Local $msg, $inc, $i, $del1

    GUICreate("My Main", -1, -1, 100, 100)
    $del1 = GUICtrlCreateButton("Delete", 50, 200, 50)
    GUISetState()
    CreateChild()

    $i = 1
    $inc = 1
;$i=5; uncomment to delete starting from last define Graphic control
;$inc=-1

    Do
        $msg = GUIGetMsg()
        If $msg = $del1 Then $i = Del($inc)

        If $msg = $del Then
            GUICtrlDelete($a[$i])
            $i = $i + $inc
            If $i < 0 Or $i > $MAXGr Then Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example

Func Del($iInc)
    GUIDelete($child)
    CreateChild()
    If $iInc = -1 Then Return 5
    Return 1
EndFunc ;==>Del

Func CreateChild()
    $child = GUICreate("My Draw")
    $del = GUICtrlCreateButton("Delete", 50, 165, 50)

    $a[1] = GUICtrlCreateGraphic(20, 50, 100, 100)
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlSetColor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90)

    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 100, 100, 50, 80)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xc0c0ff)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 350, 200, 50, 80)
    GUICtrlCreateLabel("label", 65, 100, 30)
    GUICtrlSetColor(-1, 0xff)

    $a[2] = GUICtrlCreateGraphic(220, 10, 100, 100)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90)

    $a[3] = GUICtrlCreateGraphic(220, 110, 100, 100)
    GUICtrlSetBkColor(-1, 0xf08080)
    GUICtrlSetColor(-1, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 80, 80)

    $a[4] = GUICtrlCreateGraphic(20, 200, 80, 80)
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1)

    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 30, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 70, 70)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 50)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 10)

    $a[5] = GUICtrlCreateGraphic(150, 10, 50, 50)
    GUICtrlSetBkColor(-1, 0xa0ffa0)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20); start point
; it is better to draw line and after point
; to avoid to switch color at each drawing
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 30)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 40)

    $a[6] = GUICtrlCreateGraphic(110, 260, 230, 130)
    GUICtrlSetColor(-1, 0); to display a black border line
    GUICtrlSetBkColor(-1, 0xc0c0ff)
    GUICtrlSetGraphic(-1, $GUI_GR_HINT, 3); to display control lines and end points

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff); fill in blue
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 120, 20); start point
    GUICtrlSetGraphic(-1, $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100)
    GUICtrlSetGraphic(-1, $GUI_GR_BEZIER + $GUI_GR_CLOSE, 100, 40, 40, 100, 40, 20)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 60, 30); start point

    GUISetState()
EndFunc ;==>CreateChild
Yes I have seen that example but I need an Example for what I need because I have already tryed to do it myself but I couldn't make it to work properly!

I would really need an example exactly for what I need

I need to create a chart like the one I uploaded...


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
JFee

Post the code that you tried but didn't work and maybe I can help you


Regards,Josh

Share this post


Link to post
Share on other sites
darzanmihai

Post the code that you tried but didn't work and maybe I can help you

local $left = 436
local $top = 28
local $latime = 401
local $grosime = 345
$grafic = GUICtrlCreateGraphic ( $left, $top , $latime, $grosime);, style]]] )
GUICtrlSetBkColor(-1,0xffffff)

GUICtrlSetColor($graficID,0xff0000)
$valoriDinTabel = _ArrayCreate("24")
for $i = 3 to 26
    _ArrayAdd($valoriDinTabel,GUICtrlRead($aGrid1[$i][1]))
Next
$ymax = _ArrayMax ( $valoriDinTabel ,1,1 );$ymax = 100% din inaltimea graficului
$latimebara = $latime/$valoriDinTabel[0];am stabilit latimea unei bare

For $i = 1 to 24
    $inaltime = $grosime*$valoriDinTabel[$i]/$ymax
GUICtrlSetGraphic ( $graficID, $GUI_GR_RECT, $latimebara*($i-1),$grosime-$inaltime, $latimebara,$inaltime)
GUICtrlSetColor(-1,0xff0000)
next

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
JFee

Set the color before you create the rectangle with the GUICtrlSetGraphic function.

What exactly wasn't working?


Regards,Josh

Share this post


Link to post
Share on other sites
darzanmihai

Set the color before you create the rectangle with the GUICtrlSetGraphic function.

What exactly wasn't working?

When I set the color like you suggested, it does not show anything, but if I leave it lik it is, it displays ok, but with no fill color, and if the fields of the array fave a big value, the regtangles overlaps on the Y axis

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
darzanmihai

When I set the color like you suggested, it does not show anything, but if I leave it lik it is, it displays ok, but with no fill color, and if the fields of the array fave a big value, the regtangles overlaps on the Y axis

I resolved the isue with the color, but still, if the fields values pass a certain value, the rectangles overlaps on the Y axis

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
JFee

Again, from the helpfile:

When BkColor is equal to $GUI_GR_NOBKCOLOR the drawing will not be filled. It is the default. For Color the default line color is black.

Keep a constant width for each of the bars and they won't overlap.

Regards,Josh

Share this post


Link to post
Share on other sites
darzanmihai

Again, from the helpfile:

Keep a constant width for each of the bars and they won't overlap.

The Width is kept constant and it does not overlap on the X axis, the Height varies ans it overlaps on the Y axis.....a think I should refresh the graphic with

GUICtrlSetGraphic(-1,$GUI_GR_REFRESH )

but it stil overlaps, even if I refesh after the for loop and inside the for loop....

Forgot to mention that the first time I drow the chart works fine, but the second time, the rectangles are overlaped.

I attached a screenshot to see what I mean:

Edited by darzanmihai

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
darzanmihai

The Width is kept constant and it does not overlap on the X axis, the Height varies ans it overlaps on the Y axis.....a think I should refresh the graphic with

GUICtrlSetGraphic(-1,$GUI_GR_REFRESH )

but it stil overlaps, even if I refesh after the for loop and inside the for loop....

Forgot to mention that the first time I drow the chart works fine, but the second time, the rectangles are overlaped.

I attached a screenshot to see what I mean:

couldn't attache

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
darzanmihai

#1 no screenshot attached

#2 you have your axes confused

#3 Try working on it and debugging yourself for a bit. Then if you run into more trouble let us know

#4 You still haven't deleted http://www.autoitscript.com/forum/index.php?showtopic=76469

#1 couldn't atach...not my fault

#2 Y axis is verticat and X horizontal---->>>>>>i'm not confusing

#3 hope I'll manage

#4 i will


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
darzanmihai

#1 no screenshot attached

#2 you have your axes confused

#3 Try working on it and debugging yourself for a bit. Then if you run into more trouble let us know

#4 You still haven't deleted http://www.autoitscript.com/forum/index.php?showtopic=76469

Done!

Needed to use GUICtrlDelete() and then redrew the chart!


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.