1

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);

   }
Alberto Solano
  • 7,972
  • 3
  • 38
  • 61
Cesar Downs
  • 57
  • 1
  • 3
  • 10
  • Is the `ChartPanel` in an internal frame, as discussed [here](http://stackoverflow.com/questions/8199766/how-can-i-fix-this-code-so-i-can-add-this-jfreechart-to-a-panel/8199839#8199839)? – trashgod Nov 20 '11 at 20:46
  • I can't understand nothing of what you write. What do you really want to achieve? Do you mean the resize of the panel in which the JFreeChart is contained or you mean the resizing of each portion of the chart? – Alberto Solano Nov 20 '11 at 20:51
  • I mean the panel in which the chart is in by reducing the size of the panel I assume that the chart will too – Cesar Downs Nov 20 '11 at 20:53

2 Answers2

3

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

GETah
  • 20,922
  • 7
  • 61
  • 103
1

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

Alberto Solano
  • 7,972
  • 3
  • 38
  • 61
  • 1
    This relies the `JFrame` having a default `BorderLayout` and a default destination of `CENTER`. – trashgod Nov 20 '11 at 21:17
  • @trashgod Obviously. If the OP wants a JFrame with a specified layout, he can use a Container and invoke setLayout(), but he didn't asked for it. Also, if he wants to set the position/destination of JFrame, he can invoke the setBounds() method of the JFrame class. :-) – Alberto Solano Nov 20 '11 at 21:28
  • Indeed, more information from the OP would inform a better answer. I was curious, as a [previous] question involved `JInternalFrame`, which would work similarly to your example using `JFrame`. – trashgod Nov 20 '11 at 21:37
  • @trashgod Yes, I agree that the OP should inform if he wants a better answer. I read the previous question of the OP, and your great answer, that, as you said, involved JInternalFrame. Mine is very similar to your example and I'm curious like you why the OP din't asked you for further details about resizing of the frame. – Alberto Solano Nov 20 '11 at 21:48