1

I'm trying to embedded a XChart panel in a JavaFX application.

For that I'm trying to use a swing node to add to it a xChart panel. So far it works, I can see the chart.

The problem is that I need to update it in realtime every 50 ms and if I try to add the data to the chart it won't update it until later.

    final XYChart chart = QuickChart.getChart("Simple XChart Real-time Demo", "Radians", "Sine", "sine", initdata[0], initdata[1]);    


    JPanel pnlChart = new XChartPanel(chart);

If I use a SwingWrapper:

final SwingWrapper<XYChart> sw = new SwingWrapper<XYChart>(chart);
sw.displayChart();

and use sw.repaintChart():

Platform.runLater(() -> chart.updateXYSeries("sine", data[0], data[1], null));
sw.repaintChart();

It works but the swing Wrapper creates its own window.

How could I update the data in the embedded chart instead?

Thank you.

Twistx77
  • 67
  • 8

1 Answers1

1

SwingWrapper is a class designed to pop up a standalone JFrame to display a chart and shouldn't be used as an embedded chart in a JavaFX or Swing application. Take a look at SwingDemo and use a XChartPanel in your JavaFX app instead.

herrtim
  • 2,697
  • 1
  • 26
  • 36