I’m trying to get multiple jfreecharts displaying within a single window. Apparently this is not possible with the included ChartFrame so I attempted to add multiple copies of the same chart to a JFrame which didn’t work. Any ideas?
JFrame frame = new JFrame("Chart");
frame.getContentPane().add(new ChartPanel(chart1));
frame.getContentPane().add(new ChartPanel(chart2));
frame.pack();
frame.setVisible(true);
With this code, I only get one chart in the JFrame.
EDIT:
I added another data set and chart but it still only displays one of them.
Cause of your problem is layout of
frame.getContentPane().Default layout at the
JFramecontent pane –BorderLayout. Read more aboutBorderLayouthere.This operation
equals
and add
ChartPanelto the CENTER area of the content pane. SecondChartPanelyou add to CENTER area too. Then you add two component to the same area the last added one hides all previous added. Thus second ChartPanel hides first one.You need change layout for
frame.getContentPane().You may use the same chart to two
ChartPanel.Try to change you code to
It is not code for production. It just example to show two
ChartPanelon the frame.