Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering JavaFX 2 charts in background

I have an application that is used for data analysis. A big part of the application is the ability to be able to show charts based on the data assembled, and to be able to export a large number of tasks in one batch-operation. Up until now I have used JFreeChart, but I would like to use the native JavaFX Charts so that the exported charts will still look the same as they do on-screen in the application.

I am on JavaFX 2.2.1 (jdk 7u6).

I am able to generate the charts in one batch, but that means that I have to freeze the User Interface (UI), as these charts have to be rendered on the JavaFX Application Thread. I use the Platform.runLater(new Runnable() { ... }); command for this, wrapped around the code that generates the charts.

If I instead wrap each individual chart generation into a Platform.runLater(new Runnable() { ... }); The GUI doesn't freeze up as before, but I will also get no feedback because I am unable to detect when each of the individual charts are generated (they are ran at a later stage, and I have no control over when that might happen, and there is no callback available as far as I know either).

For this particular event I would like to show a progress bar to the user, and I want this progress bar to be updated along with the actual chart generation.

Any suggestions or hints as to how this can be achieved ?

like image 777
Joachim H. Skeie Avatar asked Nov 05 '12 12:11

Joachim H. Skeie


Video Answer


1 Answers

This question was solved in the Oracle JavaFX forum thread: Render charts in background.

The solution was to have a SaveChartsTask with three subtasks:

  1. Create charts in an off screen scene graph.
  2. Take snapshots of each off screen chart to an JavaFX image.
  3. Use imageio routines to export the JavaFX images to files.

The workDone properties on tasks allowed the process of the operations to be monitored. By splitting the total work up into subtasks, keeping work off of the JavaFX application thread when possible and making use of CountDownLatches and BlockingQueues as necessary to synchronize operations, the UI was able to remain responsive.

like image 164
jewelsea Avatar answered Nov 02 '22 23:11

jewelsea