I have written a small sample application. This application tries to use Logarithmic Axis scaling first . If this - for any reason - fails, a normal scaled nuberaxis should be used:
Code: Select all
public static JFreeChart test()
{
JFreeChart chart = null;
DefaultCategoryDataset ds = new DefaultCategoryDataset();
ds.addValue(0.38, "1","A");
ds.addValue(0.07, "2","A");
ds.addValue(0.02, "3","A");
//chart = ChartFactory.createAreaChart("", "Area", "AreaChart",ds,PlotOrientation.VERTICAL, true, true, false);
chart = ChartFactory.createBarChart("", "Bar", "BarChart",ds,PlotOrientation.VERTICAL, true, true, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
try
{
NumberAxis axis = new LogarithmicAxis("ll");
axis.setAutoRange(true);
plot.setRangeAxis(axis );
}
catch (RuntimeException ex)
{
log.debug("Number Axis use in place of Logarithmic Axis because Values less than or equal to zero not allowed with logarithmic axis ",ex);
NumberAxis axis = new NumberAxis("yy");
axis.setAutoRange(true);
plot.setRangeAxis(axis );
}
return chart;
}
Code: Select all
java.lang.RuntimeException: Values less than or equal to zero not allowed with logarithmic axis
at org.jfree.chart.axis.LogarithmicAxis.autoAdjustRange(LogarithmicAxis.java:530)
Usind the createAreaChart ( as used in the line disabled by commenting out) I did not get th is exception on this place - but I get an Exception (for every of the 3 values) and as result a chart without values:
Code: Select all
sun.dc.pr.PRException: endPath: bad path
at sun.dc.pr.Rasterizer.endPath(Rasterizer.java:537)
at sun.java2d.pipe.DuctusRenderer.createShapeRasterizer(DuctusRenderer.java:374)
at sun.java2d.pipe.DuctusShapeRenderer.renderPath(DuctusShapeRenderer.java:57)
at sun.java2d.pipe.DuctusShapeRenderer.fill(DuctusShapeRenderer.java:49)
at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2160)
at org.jfree.chart.renderer.category.AreaRenderer.drawItem(AreaRenderer.java:295)
at org.jfree.chart.plot.CategoryPlot.render(CategoryPlot.java:2796)
at org.jfree.chart.plot.CategoryPlot.draw(CategoryPlot.java:2613)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1214)
at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1388)
at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1368)
at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:171)
at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:124)
Jens