getChartRenderingInformation() getScreenDataArea() both null

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mechko
Posts: 2
Joined: Wed Jun 18, 2008 3:38 pm

getChartRenderingInformation() getScreenDataArea() both null

Post by mechko » Wed Jun 18, 2008 4:01 pm

Hej,

I'm trying to convert Java2D-Coordinates from a ChartMouseEvent to the coordinates of my XYPlot. I know that I have to use java2DToValue(). But the required Rectangel2D returned by ChartPanel.getScreenDataArea() returns always only zero-values.

JFreeChart chart = e.createChart();
ChartPanel cp = new ChartPanel(chart);
System.out.println(cp.getScreenDataArea().toString())

--> java.awt.geom.Rectangle2D$Double[x=0.0,y=0.0,w=0.0,h=0.0]

When I try to use the return value of getPlotArea() from getChartRenderingInformation() I even get a NullPointerException:

System.out.println(cp.getChartRenderingInfo().getPlotInfo().getPlotArea().toString());

The JFreeChart chart is correct as far as I can tell - i.e. there are no visible errors when displaying exactly this entity.

Thanks in advance,
mechko

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: getChartRenderingInformation() getScreenDataArea() both

Post by paradoxoff » Wed Jun 18, 2008 7:01 pm

mechko wrote: JFreeChart chart = e.createChart();
ChartPanel cp = new ChartPanel(chart);
System.out.println(cp.getScreenDataArea().toString())

--> java.awt.geom.Rectangle2D$Double[x=0.0,y=0.0,w=0.0,h=0.0]
Try to paint your ChartPanel before you retrieve the information.

mechko
Posts: 2
Joined: Wed Jun 18, 2008 3:38 pm

Re: getChartRenderingInformation() getScreenDataArea() both

Post by mechko » Thu Jun 19, 2008 10:24 am

Try to paint your ChartPanel before you retrieve the information.
Thanks. I tried to call ChartPanel.repaint() with no success as well.

What I just tested was using a ChartComposite instead of the
SWT_AWT Method:

Code: Select all

final ChartComposite frame = 
      new ChartComposite(parent, SWT.NONE, chart, true);			
 frame.redraw();
 System.out.println(frame.getScreenDataArea().toString());
The output is "Rectangle {0, 0, 0, 0}". It's driving me mad. As I said, the ChartComposite including the chart is painted and displayed correctly.

There is also another question concerning this issue: How do I get the instance of ChartPanel or ChartComposite from within a ChartMouseEvent? I know event.getChart(), but is there a way to get the surrounding Panel?

Thanks once more,
mechko




[/code]

heprom
Posts: 91
Joined: Sat May 27, 2006 4:25 am
Location: Paris

Post by heprom » Tue Jul 01, 2008 8:39 pm

Hi mechko,

frame.redraw() might not work, try

Code: Select all

frame.forceRedraw()
It does work, I tried with the simple demos shipped with jfreechart. for instance with SWTTimeSeriesDemo I get: Rectangle {59, 31, 521, 170}
HTH,
Henry

deryaaltuntas
Posts: 4
Joined: Thu Dec 15, 2011 10:31 am
antibot: No, of course not.

Re: getChartRenderingInformation() getScreenDataArea() both

Post by deryaaltuntas » Sat Feb 18, 2012 8:50 am

I have same problem.It only returns zero values for my case.
But I am using ChartPanel instance with CombinedRangeXYPlot in it.
ConbinedRangeXYPlot has 2 subplots in it

This code gives java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Code: Select all

chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();
This code gives returns zero values java.awt.geom.Rectangle2D$Double[x=0.0,y=0.0,w=0.0,h=0.0]

Code: Select all

chartPanel.getScreenDateArea() 
This code to get second subplot in x axis gives returns zero values java.awt.geom.Rectangle2D$Double[x=0.0,y=0.0,w=0.0,h=0.0]

Code: Select all

chartPanel.getScreenDateArea(1, 0)  

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: getChartRenderingInformation() getScreenDataArea() both

Post by John Matthews » Sun Feb 19, 2012 7:44 pm

Cross-posted here.

Locked