Martyn_HK

unread,
Oct 29, 2016, 9:52:21 AM10/29/16
to mitappinv...@googlegroups.com

A short while ago Nocola C made a post about graphs. His original post, here, is now closed so I cannot add to it.

Attached is an example of a scrolling graph. I wrote this a while ago and have just cleaned it up to make it more adaptable. It works but I am not sure it is 100% reliable.

The graph starts at the left hand side and once the line reaches the right side the graph will scroll.



The graph (canvas) size can be changed. In the example the width is based on a screen percentage (94%). The height is set by using a global variable.


The graph x resolution (in pixels) is also set through a global variable. If you use a very small resolution you may need to increase the list size in the screen1.initialize function.
If the list is too short, not long enough to accommodate the total number of x points, the app will crash. The list length could be calculated from the canvas width and the resolution if required.

The change orientation function is a little clunky and can be improved. I had to use a timer to get the new screen width. Without it the screen width does not update in time.

The value to be plotted has to be within a set range (positive only), this is set using global variables (minVal, maxVal). The app uses the range and the canvas size to remap the value to fit the canvas.

The very first value is not plotted until there is a value 2. This means the first line drawn is value1 to value2, not 0 to value1. Since the graph did what I wanted I never changed this.

 

 

The app as it stands is not particularly efficient and could be made to run faster.


scrollingGraph_05.aia
graph_01.jpg
graph_02.jpg

Taifun

unread,
Oct 29, 2016, 10:40:55 AM10/29/16
to MIT App Inventor Forum
thank you very much! keep up the good work!
Taifun

Abraham Getzler

unread,
Oct 29, 2016, 9:19:24 PM10/29/16
to MIT App Inventor Forum
(added to the Graphs section of the Power Users FAQ)
ABG

Reply all
Reply to author
Forward
0 new messages