如何在 jfreechart、netbeans 中调整此图表的大小?

发布于 2024-12-17 03:54:23 字数 1044 浏览 2 评论 0原文

我似乎无法操纵图表本身。我无法更改大小,并且 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-12-24 03:54:23

您不必担心图表大小,将面板布局设置为 GridBagLayout 应该有帮助。

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

江挽川 2024-12-24 03:54:23

您是否已将面板 chartPanel 添加到 JFrame 中?

如果没有,请尝试以下操作:

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

正如您从代码中看到的,您可以使用 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 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文