如何在 jfreechart、netbeans 中调整此图表的大小?
我似乎无法操纵图表本身。我无法更改大小,并且 chartPanel = createChartPanel();
不断重写为 chartPanel = javax.swing.panel();
我尝试创建一个方法 modificarGrafico
,但什么也没有:
示例: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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必担心图表大小,将面板布局设置为 GridBagLayout 应该有帮助。
You don't have to worry about your chart size, set your Panel's layout to GridBagLayout that should help.
您是否已将面板
chartPanel
添加到JFrame
中?如果没有,请尝试以下操作:
正如您从代码中看到的,您可以使用
jf.setSize(frame_width,frame_height);
jf.setSize(frame_width,frame_height); 编辑包含chartPanel
的框架的大小。代码>.您可以看一下这些 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
Have you added your panel
chartPanel
to aJFrame
?If not, try this:
As you can see from code, you can edit the size of the frame in which the
chartPanel
is contained, withjf.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