Getting chart and data area dimensions unreliable?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Getting chart and data area dimensions unreliable?

Post by dunabur » Tue Nov 14, 2017 2:37 pm

Hey there,

I`ve been trying to get the chart dimensions as described here:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=28208

Basically I have a chartPanel inside a JFrame, using a CandlestickRenderer.
I used Componentlistener to execute code each time I resize the window, to give me the Chart Dimensions:

Code: Select all

@Override
	public void componentResized(ComponentEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println("WINDOW RESIZED!");
		System.out.println( chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea());		
                System.out.println( chartPanel.getChartRenderingInfo().getPlotInfo().getPlotArea() );

	}
Now, when I resize the window, at first the pixels seem to reflect the dimensions on the monitor, but after a certain limit (which is about 932), the width value does not increase any longer, even though I can stretch the chart wider.
I suspect that after a certain width the chart only gets stretched, therefore there is no update on the dimensions? How can I stop stretching it and make it render over the whole range?

I actually need the dimensions (especially the width) to calculate how many data items should be displayed with domainAxis.setRange(), but this does not work if there is an artificial limit to the width feedback.

Thanks in advance for your feedback!

EDIT:
I suspected that it is maybe the default width and height for chartPanel that is causing this, overriding its gePreferredSize to set width and height to 2000, but the dimensions max out at width=932,height=720 when calling chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(). dimensions seem to max out at(even though the chart gets streched more):
java.awt.Rectangle[x=84,y=6,width=932,height=720]
java.awt.geom.Rectangle2D$Double[x=8.0,y=6.0,w=1008.0,h=758.0]

dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Re: Getting chart and data area dimensions unreliable?

Post by dunabur » Tue Nov 14, 2017 3:05 pm

Apparently chartPanel.setMaximumDrawWidth and chartPanel.setMaximumDrawHeight were set to their default of 1024x768 after which the chart would only stretch but not keep rendering.

Setting chartPanel.setMaximumDrawWidth() and chartPanel.setMaximumDrawHeigh() to higher levels will push the rendering limit far away enough so that it does not become a problem. This way the chart and data area dimensions will be reliable until those newly set dimensions are hit.

Locked