2

I have a Swing JFrame with a ChartPanel as its only component. When I resize the frame, the chart panel gets stretched out as if it were an image. For example, if I shrink it vertically, all of the character get compressed.

Is it possible to have the ChartPanel redraw itself on resize events so that it shows more detail on the graph, instead of getting stretched as a static image?

Bill
  • 44,502
  • 24
  • 122
  • 213

3 Answers3

5

You have to change a few options when constructing your ChartPanel :

 * @param minimumDrawWidth  the minimum drawing width.
 * @param minimumDrawHeight  the minimum drawing height.
 * @param maximumDrawWidth  the maximum drawing width.
 * @param maximumDrawHeight  the maximum drawing height.
ADR
  • 51
  • 1
  • 2
3

I had the same issue. I now realize that ADR gave the solution: you have to set the minimum and maximum drawing width and height, for example:

chartPanel.setMinimumDrawWidth( 0 );
chartPanel.setMinimumDrawHeight( 0 );
chartPanel.setMaximumDrawWidth( 1920 );
chartPanel.setMaximumDrawHeight( 1200 );
1

ChartPanel has methods to control zoom, as shown in this example. I don't see characters getting compressed.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • restoreAutoBound() breaks my manually-set range of Y axis. And which method controls the zooming from your example? I also get the text stretched or compressed when I resize the Window. (I have a JFrame Window, with a TabPanel, and a tab with a JPanel inside, and the JPanel contains the JFreeChart's ChartPanel; everything resizes with the JFrame). – Dante WWWW Oct 18 '11 at 02:48
  • `ChartPanel` manages the zooming. Pose a question with your [sscce](http://sscce.org/) that exhibits the problem you describe. See also [`ThermometerDemo`](http://stackoverflow.com/questions/7597015/changing-mercury-color-in-thermometer-in-jfreechart/7602126#7602126) and [`BoxAndWhiskerDemo`](http://stackoverflow.com/questions/6844759/jfreechart-scaling-of-boxplots-with-several-categories/6849654#6849654). – trashgod Oct 18 '11 at 02:59
  • I just want to ask, in your example, after you click the Maximium button of the window, won't the whole chart get stretched or compressed? At least, when I ran your example and maximium the window, I saw characters as well as everything else in the chart stretched. – Dante WWWW Nov 22 '11 at 07:50