Forums Register Login

ChangeListener - Graph Data To XYChart In Realtime

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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()?

+Pie Number of slices to send: Send
Can someone please explain to me how I can implement the runLater() function...?
+Pie Number of slices to send: Send
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]
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2645 times.
Similar Threads
Arduino and JavaFX
JavaFX Scene Builder Help with Charts and such
how to call JavaFX_Charts from a java GUI
how to add value against each listview item
Trying to populate data from database in tableview using javafx mvc architecture.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:20:14.