Plot org.knowm.xchart.XYChart in same working JFrame

506 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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

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

It should work :)