简体   繁体   中英

JFreeChart - Adding more than one ChartPanel in the same JPanel

I need to add two chartPanels in a same JPanel.

I did this for a single chartPanel, and it worked:

JPanel content = new JPanel(new BorderLayout());
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
content.add(chartPanel); 

But I tried to add the second chartPanel doing this:

   JPanel content = new JPanel(new GridLayout(0,2));
   final ChartPanel chartPanel = new ChartPanel(chart);
   chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
   content.add(chartPanel);

   final ChartPanel chartPanel2 = new ChartPanel(chart);
   chartPanel2.setPreferredSize(new java.awt.Dimension(500, 270));
   content.add(chartPanel2);

But when I do this, both graphs are displaying in a wrong way, like only a line or something, why this is happening?

Use the ChartPanel constructor that lets you specify the preferred size, as shown here . Alternatively, override getPreferredSize() , as shown here .

此搜索

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM