Hello,
I wanted to use an XYImageAnnotation in a Chart. I'm using JFreeChart with SWT, so ChartComposite is my Container, where I put the Chart.
The problem was, that XYImageAnnotations didn't apear in the chart, while other Annotations like TextAnnotations appeared.
So after a few hours of debugging I found out, that using SWT, the object g2 in XYImageAnnotation.draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) is of the class org.jfree.experimental.swt.SWTGraphics2D. And in this class, some Methods are just Auto-generated method stubs and not implemented. For example
public boolean drawImage(Image image, int x, int y,
ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
Thats why XYImageAnnotations with SWT don't apear.
Could anyone who has access to the sourcecode please change this methods, so that they throw something like 'NotYetImplementedException'? This would save a lot of time for other developers with the same problem.
Thanks a lot,
Rudi
XYImageAnnotation with SWT
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Sorry for the trouble, Rudi, although that is one of the perils of using code that is marked 'experimental'. The good news is that I committed a fix to the SWTGraphics2D class a day or two back, and it now draws the images (although I should go and test the image annotation class explicitly). So when JFreeChart 1.0.9 is released (probably around mid-December), this problem will be gone.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Rudi, David,
I've tried the XYImageAnnotation with the latest code and it does not work.
Actually it's almost working, I've traced down the bug to be a bad x, y location generated in the draw call:
will generate
Hardcoding an appropriate (x,y) location draws the image successfully. It should be easy to fix but it's late and I do not want to break anything in the awt code. Will look at this more during the week end.
Regards
/heprom
I've tried the XYImageAnnotation with the latest code and it does not work.
Actually it's almost working, I've traced down the bug to be a bad x, y location generated in the draw call:
Code: Select all
xx = xx - (float) anchorPoint.getX();
yy = yy - (float) anchorPoint.getY();
System.out.println("drawing at x="+xx+" and y="+yy);
boolean b = g2.drawImage(this.image, (int) xx, (int) yy, null);
Code: Select all
drawing at x=-11060.547 and y=384.78647
Regards
/heprom
ok here's how to fix it:
we need relative XY coordinates like with the XYTitleAnnotation class
David, I can patch this. Do we want to add a XYCoordinateType field to the class like in XYTitleAnnotation?
/heprom
we need relative XY coordinates like with the XYTitleAnnotation class
Code: Select all
Range xRange = domainAxis.getRange();
Range yRange = rangeAxis.getRange();
double anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
double anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
// double anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
// double anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
/heprom
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Yes, I think that would add to the flexibility of XYImageAnnotation. Right now, you can only specify the image location using the coordinates of the axis. Being (optionally) able to place it at a relative location within the plot area would be useful if you want to show a logo at, say, the bottom right of the chart. And linking to a dataset series and item index would allow the image to "follow" a particular data point.heprom wrote:David, I can patch this. Do we want to add a XYCoordinateType field to the class like in XYTitleAnnotation?
Having said all that, I just tested XYImageAnnotation with the latest SWTGraphics2D class and it seems to be working. What was the failure you saw?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Hmm, interesting, The failure I described in the above post was not due to SWT but in the XYImageAnnotation code. Apparently you do not seem to see it. With the code from svn head, the image (the anchor is set to something usual) is drawn at and thus do not appear on the chart. If you hardcode say x=100, y=100, the image appears. I'll post some demo code tonight.
Code: Select all
drawing at x=-11060.547 and y=384.78647