Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ChangeListener - Graph Data To XYChart In Realtime

 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having difficulty with the ChangeListener portion of my code. My goal is to read data (wattage generated) from a small solar panel and stream this data to an XYChart.Series in JavaFX. My xAxis of the chart range is 0-15 (hours) which I would like to be represented as 6a.m. to 9 p.m. for the xAxis tick marks. Is it possible to read and graph the arduino data every 10 minutes (6x/hour)? Any ideas on how to go about setting this one up within the JavaFx class?

I have tested my SerialPort connection with the arduino and I am able to readBytes and print them in the compiler. Now, should I create an ObservableList of the following form: ObservableList<XYChart.Series<String, Number>> xyList1 = FXCollections.observableArrayList();
in order to record the data?


If this is not clear, please let me know and I will do my best to clarify. I could really use some help with this.
 
John Damien Smith
Ranch Hand
Posts: 298
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing the right thing. What is the issue?

You will be receiving new data from the serial port (on a separate thread from the JavaFX application thread).

Once you have the data, invoke Platform.runLater(() -> xyList1.add(new XYChart.Data(xval, yval)) that will ensure you modify the observable list that backs the chart on the JavaFX application thread.

Because it is an observable list you don't need to create an change listeners or anything like that, the chart will already be observing the list and when it changes will automatically update itself.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently, I'm using readBytes (SerialPort class) to get the data from the arduino. I'm not sure how to process that data into the chart format (indicated above) using xyList1.add(new XYChart.Data(xval, yval)). How will I get the xval and yval? If I append it to a StringBuilder, would I use set/get methods then to retrieve the collected data on each cycle (for example, every 5 minutes).

My goal with this project is to have 2 sensors processing data simultaneously, and displaying that data using Java...will I chart both sensor's data within a single Platform.runLater()?

Thank you for your help. Most of what I've found on the subject as been from other project I've found online. If I used something like the following, where would I place the Platform.runLater()?

 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain to me how I can implement the runLater() function...?
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the example I've found from JavaFX8 Introduction By Example Written by: Carl Dea, Merk Heckler, Gerrit Grunwald, Jose Pereda, and Sean Phillips
How would I represent t1 without using the Lambda format used here? I'm setting up a separate method actionPerformed because it is easier for me to read and I will call the method when the start button is pressed.


Screen Shot 2015-04-10 at 4.28.35 PM.jpg
[Thumbnail for Screen Shot 2015-04-10 at 4.28.35 PM.jpg]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic