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
getChartRenderingInformation() getScreenDataArea() both null
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: getChartRenderingInformation() getScreenDataArea() both
Try to paint your ChartPanel before you retrieve the information.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]
Re: getChartRenderingInformation() getScreenDataArea() both
Thanks. I tried to call ChartPanel.repaint() with no success as well.Try to paint your ChartPanel before you retrieve the information.
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());
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]
Hi mechko,
frame.redraw() might not work, try
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
frame.redraw() might not work, try
Code: Select all
frame.forceRedraw()
HTH,
Henry
-
- Posts: 4
- Joined: Thu Dec 15, 2011 10:31 am
- antibot: No, of course not.
Re: getChartRenderingInformation() getScreenDataArea() both
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
This code gives returns zero values java.awt.geom.Rectangle2D$Double[x=0.0,y=0.0,w=0.0,h=0.0]
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]
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();
Code: Select all
chartPanel.getScreenDateArea()
Code: Select all
chartPanel.getScreenDateArea(1, 0)
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm