开发者

How can I have a jfreechart ChartPanel automatically enlarge itself?

开发者 https://www.devze.com 2023-02-28 20:38 出处:网络
I have a Swing JFrame with a ChartPanel as its only component. When I resize the frame, the chart panel gets stretched out开发者_StackOverflow as if it were an image. For example, if I shrink it verti

I have a Swing JFrame with a ChartPanel as its only component. When I resize the frame, the chart panel gets stretched out开发者_StackOverflow 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?


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号