Android Question Plot with new data every time user presses a button

Meigionel TS

Member
Licensed User
I was looking at https://www.b4x.com/android/help/mpchartlib.html#linechart and was wondering if it is possible to insert new graph data when a button is pressed. One odd thing that I found in this and other graphs, I cannot mention any particular coordinate on a graph, unlike matplotlib. I am looking for a way to draw a graph and then placing (or appending new coordinates) to the graph when a user presses a button, the plot points (x and y values) could be in an array, when a button is pressed, new coordinates are appended to the existing plot.

I also found this interesting https://www.b4x.com/android/forum/t...ta-passed-from-b4a-project.61521/#post-388909 but I cannot understand how to exactly pass new (X and Y axis data). In fact I could not understand how to set both X axis range and Y axis range at the same time and yet pass new coordinates. Please help me here.

I am attaching a sample graph which I made in python, I am looking for something like it.

In that graph, I can change the pointer's location (the one with "+" symbol) by feeding new data (x, y values) from input boxes.
I can also plot line graph from one location to the other, by appending two x,y values one after another.




I looked a lot for an example in this forum which would even slightly resemble what I am trying to do, but I could not find.
 
Last edited:

Meigionel TS

Member
Licensed User
Can you provide me a simple example of how I can insert new data to a canvas with button press, I looked into the UserGuide, and perhaps, I can do it but just that I need a hint of where to start? Thank you!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can you provide me a simple example of how I can insert new data to a canvas with button press ...
You cannot.
A canvas is a tool to draw graphics, it is not a charts tool.
You need to memorize the coordinates of the points.
You need to draw everything on your own.
You would need three canvases.
One for the 'background' graphic with the scales.
One for the points, if you dont want them on the background graph.
One for the cursor.
Then you have a tricky point, the logarithmic x scale.

Is the background graph alway the same?
How is your data structure to memorize the points?
How do you determine the lines to draw?
 
Upvote 0

Meigionel TS

Member
Licensed User
Is the background graph alway the same?
The background graph is always the same.

How is your data structure to memorize the points?
When ever the button is pressed it would save the current point in a database (sqlite3) file, the sqlite file would have both the xaxis and yaxis points.
How do you determine the lines to draw?
I wish I could show you how I accomplished this in python. Is there a way to convert python to B4A? I guess not though.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Is there a way to convert python to B4A?
Not that I know.
I don't know Python, but you can show us how you did it. It's always interesting to learn.
I explain more in detail my question on about how you determine the lines to draw.
You say that you have points and you want do draw lines. Could you elaborate this sentance:
I can also plot line graph from one location to the other, by appending two x,y values one after another.
 
Upvote 0

Meigionel TS

Member
Licensed User
I am posting a video on youtube of how my python program works.

Could you elaborate this sentance
It may be clumsy if I explain like this.

PS. Please ignore the background song in the video, I did not realize that there was a song playing in the background.
 
Last edited:
Upvote 0

Meigionel TS

Member
Licensed User
Yeah, it is but can you point me at any direction of where to start, like how to add points using keypress. I am willing to share the whole project here if I could start with it.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a demonstrator project.
It does what you want, but only for one graph.
It is easy to make it for two graphs, working with arrays.
If you want, I can do it for you.
I suppose that your project is dedicated for tablets only.
I developped this project on a phone.

upload_2017-12-30_10-15-4.png
 

Attachments

  • EarControl.zip
    9.6 KB · Views: 926
Upvote 0

Meigionel TS

Member
Licensed User
Bravo! That's just what I needed. Thank you very much! Yes, I believe I can do it with both the graphs. I am going to release the whole project here once it is completed. Thank you once again!
 
Upvote 0

killiak

Member
Licensed User
Longtime User
Attached you find a demonstrator project.
It does what you want, but only for one graph.
It is easy to make it for two graphs, working with arrays.
If you want, I can do it for you.
I suppose that your project is dedicated for tablets only.
I developped this project on a phone.

View attachment 63255

OMG....Simply put it...


That has to be something.

With that knowledge...you have to create a CEP software....
 
Upvote 0
Top