Getting chart and data area dimensions unreliable?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

Getting chart and data area dimensions unreliable?

Postby dunabur » Tue Nov 14, 2017 2:37 pm

Hey there,

I`ve been trying to get the chart dimensions as described here:

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
   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!

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):
Posts: 13
Joined: Sat Jun 24, 2017 12:05 pm

Re: Getting chart and data area dimensions unreliable?

Postby 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.
Posts: 13
Joined: Sat Jun 24, 2017 12:05 pm

Return to JFreeChart

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 5 guests