Skip to first unread message

Narayanan Subramanian

unread,
Jun 16, 2017, 8:35:33 AM6/16/17
to MIT App Inventor Forum
I want to draw a graph based on some input data. So for the graph scale, I am dividing the screen width and screen height by the maximum x value and maximum y value. If I use canvas.height or canvas.width it gets zero for canvas height and canvas width and so errors out. If I use screen1.height or screen1.width, it is not drawing the x or yaxis. This program has multiple screens to connect to wifi and get data. In the attached file, I have removed those extraneous material to test the graph portion. So when I call the canvas, I set canvas.visible to true. I thought canvas.width should return the width of the screen. Is there a bug? Also, in the attached, what is wrong? Why is it not drawing the x and y axes?
Test_GraphScreen.aia

Evan Patton

unread,
Jun 16, 2017, 1:19:05 PM6/16/17
to MIT App Inventor Forum
Hi Narayanan,

If you are setting Visible to True you cannot immediately get the width and height because the screen needs to first relayout (making the canvas visible could trigger things below it to move in the view hierarchy). Therefore if you immediately read the width/height they will be 0 since this was true when they were invisible. You will need to do something like enable a Clock after you set the view visible whose Timer event will perform the rest of your computations. In the Timer event you can disable the clock since it has served its purpose.

Evan
Reply all
Reply to author
Forward
0 new messages