I want to visualize a static chart with 10 rows, each of which has 10,000 points using JavaFX. After my first tests, I'm a little worried about the performance of the JavaFX diagram APIs, especially the constructor new XYChart.Series<>(...), which takes 3 minutes to initialize for 100,000 data points.
If you do not believe me, run the following code:
public static final int SIZE = 100000;
public static void main(String[] args) {
List<XYChart.Data<Integer, Integer>> data = new ArrayList<>(SIZE);
measureTime("creating list", () -> {
for (int i=0; i<SIZE; i++) {
data.add(new XYChart.Data<>(i, i));
}
});
measureTime("creating series", () -> {
new XYChart.Series<>(FXCollections.observableList(data));
});
}
public static void measureTime(String msg, Runnable f) {
long start = System.nanoTime();
f.run();
long end = System.nanoTime();
System.err.println("Time for " + msg + ": " + (end - start) / 1000000 + " ms");
}
These are the results on my computer:
Time for creating list: 62 ms
Time for creating series: 173555 ms
Why does this initialization take too long and how can I get around this?
Or is there a way to use JavaFX diagrams without Observables?
source
share