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

Discussion in 'Android Questions' started by Meigionel TS, Dec 29, 2017.

  1. Meigionel TS

    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: Feb 14, 2018
  2. klaus

    klaus Expert Licensed User

    I'm afraid that you won't find an existing library doing what you want to do.
    You will need to do it on your own with canvases.
     
  3. Meigionel TS

    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!
     
  4. klaus

    klaus Expert Licensed User

    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?
     
  5. Meigionel TS

    Meigionel TS Member Licensed User

    The background graph is always the same.

    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.
    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.
     
  6. klaus

    klaus Expert Licensed User

    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.
     
  7. Meigionel TS

    Meigionel TS Member Licensed User

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

    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: Feb 14, 2018
  8. klaus

    klaus Expert Licensed User

    It's clear now.
    All this can be done with canvases.
    But this a whole project.
     
    Last edited: Dec 29, 2017
    Peter Simpson likes this.
  9. Meigionel TS

    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.
     
  10. klaus

    klaus Expert Licensed User

    Leave me some hours.
     
    Peter Simpson and metrick like this.
  11. klaus

    klaus Expert Licensed User

    Just a question, did you remove the video, I get the message video no more available.
    I hadn't saved it.
    Maybe you could post it in a private message.
     
  12. Meigionel TS

    Meigionel TS Member Licensed User

    yes. I am posting it as a message
     
  13. Meigionel TS

    Meigionel TS Member Licensed User

    Anyone who want to see the video, please ping me privately.
     
  14. Meigionel TS

    Meigionel TS Member Licensed User

    Replied you privately.
     
  15. klaus

    klaus Expert Licensed 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
     

    Attached Files:

  16. Peter Simpson

    Peter Simpson Expert Licensed User

    This works really well @klaus, really well indeed and you created it really quickly too.
     
    Johan Schoeman likes this.
  17. Meigionel TS

    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!
     
  18. killiak

    killiak Member Licensed User

    OMG....Simply put it...


    That has to be something.

    With that knowledge...you have to create a CEP software....
     
    Meigionel TS likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice