问题
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