How to resize this chart in jfreechart, netbeans?

巧了我就是萌 提交于 2019-12-02 10:57:36

问题


I can't seem to manipulate the chart itself. I can't change the size and chartPanel = createChartPanel(); keeps rewriting into chartPanel = javax.swing.panel();

I tried to create a method modificarGrafico, but nothing:

Example : http://www.flickr.com/photos/63259070@N06/6371596517/

public JPanel createChartPanel(){
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("Toyota", new Integer(10));
pieDataset.setValue("Nissan", new Integer(25));
pieDataset.setValue("Hummer", new Integer(5));
pieDataset.setValue("BMW", new Integer(10));
pieDataset.setValue("Honda", new Integer(30));
pieDataset.setValue("Ford", new Integer(20));
JFreeChart chart = ChartFactory.createPieChart3D("Ventas por Marca", pieDataset, true,         true, true);
return new ChartPanel(chart);
}

public void modificarGrafico(){
//JDesktopPane dtp = new JDesktopPane();

   this.chartPanel.setSize(200,200);
   this.chartPanel.setVisible(rootPaneCheckingEnabled);

   }

回答1:


You don't have to worry about your chart size, set your Panel's layout to GridBagLayout that should help.




回答2:


Have you added your panel chartPanel to a JFrame?

If not, try this:

JFrame jf = new JFrame("Chart");
jf.add(chartPanel);
jf.pack();
jf.setSize(frame_width,frame_height);
jf.setVisible(true);

As you can see from code, you can edit the size of the frame in which the chartPanel is contained, with jf.setSize(frame_width,frame_height);.

You can just take a look to these API:

JFrame API : http://download.oracle.com/javase/6/docs/api/javax/swing/JFrame.html

JPanel API : http://download.oracle.com/javase/6/docs/api/javax/swing/JPanel.html



来源:https://stackoverflow.com/questions/8204544/how-to-resize-this-chart-in-jfreechart-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!