We use JFreeChart to create a chart display engine. This is a web service that runs on Tomcat + Java 1.5.0 and displays charts for PNG and JPEG (using ChartUtilities.writeChartAs {PNG, JPEG} ()).
We ran into a problem when JFreeChart seems to scale everything inside the Plot area, but only by a few pixels. As a result, the graph looks inconsistent, for example:
- Minor ticks sometimes stretch horizontally, so that they appear to be two pixels wide instead of one.
- We use the small image in the upper right corner of the chart area as a watermark. This is stretched one pixel horizontally and vertically somewhere nearby (but not quite) with its middle.
- The background grid lines appear to appear at the borders of the subpixels. I did not find a way to create a precisely dashed grid line.
We tried both 1.0.9 and 1.0.13 with exactly the same results (except for small ticks that were not available in the old version). In addition, rendering the image in Frame instead of JPEG / PNG gave an identical result.
Help with thanks, in advance :)
EDIT: SSCCE:
@Test
public void testScaling1() throws InterruptedException {
Component dummy = new Component() {};
MediaTracker tracker = new MediaTracker(dummy);
Image img = Toolkit.getDefaultToolkit().getImage("C:\\My\Image.gif");
tracker.addImage(img, 0);
tracker.waitForAll();
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries ts = new TimeSeries("Sample");
ts.add(new Second(0, 0, 0, 1, 1, 1900), 1.0);
ts.add(new Second(1, 0, 0, 1, 1, 1900), 3.0);
ts.add(new Second(2, 0, 0, 1, 1, 1900), 4.0);
ts.add(new Second(3, 0, 0, 1, 1, 1900), 2.0);
dataset.addSeries(ts);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"blabla",
null,
null,
dataset,
true,
true,
false
);
XYPlot xy = chart.getXYPlot();
xy.setBackgroundAlpha(0.0F);
xy.setBackgroundImage(img);
xy.setBackgroundImageAlignment(Align.NORTH_WEST);
xy.setBackgroundImageAlpha(1.0F);
paintChart(chart);
}
Use an image with text in a small font or grid. This will show the zoom effect on the background image.
Edit 2: We resorted to subclassing or proxying Renderers and drawing a label in the text in the drawItem () (or similar) methods. It works well. However, minor ticks are now a problem - they also seem to become scalable. For example: see the 9th and 15th tics.
http://img14.imageshack.us/img14/3625/76676732.jpg