0

I want to plot org.knowm.xchart.XYChart data in same working JFrame but nothing happens in code below:

        final XYChart chart = new XYChartBuilder()
                .height(jPanel1.getHeight())
                .width(jPanel1.getWidth())
                .title("test").xAxisTitle("X").yAxisTitle("Y").build();
        
        chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Line);
        chart.getStyler().setLegendVisible(false);

        for (int i = 0; i < data.length; i++) {
            chart.addSeries(data[i], info, xyData[i]);
        }
        chart.getStyler().setMarkerSize(0);
        
       SwingUtilities.invokeLater(() -> {
           jPanel1 = new XChartPanel<>(chart);
           jPanel1.invalidate();
        });

jPanel1 is anchored in botton of Jframe. All examples of org.knowm.xchart.XYChart show graphs in new window.

blong
  • 2,815
  • 8
  • 44
  • 110
user1801745
  • 391
  • 2
  • 18

1 Answers1

0

I think you need to add his own Panel to yours;

JPanel chartPanel = new XChartPanel<XYChart>(chart);       
panel1.add(chartPanel);

It should work :)

maloomeister
  • 2,461
  • 1
  • 12
  • 21