AreaChart with logarithmic Axes not rendered

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jj
Posts: 4
Joined: Tue Feb 13, 2007 2:47 pm
Location: Germany

AreaChart with logarithmic Axes not rendered

Post by jj » Tue Nov 20, 2007 4:50 pm

I am using JFreeChart 1.0.7. in a JSF Enviorment (like jfreeChart ) to view some data from out datawarehouse, but I have some trouble using logarithmic scaled axis and the area charts.
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;

}
This works fine for the diagram type "Barchart" - I get the this Runtime Exception in the Line plot.setRangeAxis(axis ) as expected.

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)
After this exception a NumberAxis is used and the diagram is displayed correctly.


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)
Give it a solution for this problem?

Jens

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Nov 20, 2007 5:59 pm

This is a well known bug in the JDK. The JDK is not able to handle shapes that are very small or very large - in either case it throws that Exception. The only known workaround is not to render small shapes (which is not a valid workaround here).

There is nothing you or we can do - the Bug has been there since JDK 1.2 and is very likely that it will stay here for JDK 50.0 or longer. (If the USS Enterprise is Java-powered, they surely enjoy the same bug in a couple of centuries while fighting Klingons.)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Nov 20, 2007 6:14 pm

Actually, I probably can find a workaround for this specific case which I suspect is due to 0.0 not being a valid value against the logarithmic axis...but first I have to deal with the bugs in the PiePlot labelling.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jj
Posts: 4
Joined: Tue Feb 13, 2007 2:47 pm
Location: Germany

Post by jj » Wed Nov 21, 2007 10:02 am

The problem is not the well known Bug in the JDK, but the exception in setRangeAxis , especial the missing exception in case of AreaChart.

I can use a non logarithmic axis, when the logaritmic axis is not possible.

I don't understand , that the Exception in plot.setRangeAxis(logarithmicaxis ) is dependend on the chart type. Bar and stackedArea release a exception, AreaChart doesn't.

Jens

nmdxpc
Posts: 1
Joined: Fri Oct 21, 2016 3:11 am
antibot: No, of course not.

Re: AreaChart with logarithmic Axes not rendered

Post by nmdxpc » Fri Oct 21, 2016 3:14 am

Hi, I encounter the same problem recently, do you have found a solution?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: AreaChart with logarithmic Axes not rendered

Post by david.gilbert » Mon Oct 24, 2016 10:08 pm

I don't think this was ever fixed. The problem is that the base of the area is at zero but that's not a valid value on a log axis. I'm probably not going to have time to look at that in the near future, but if someone wants to send a pull request that would be welcome.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked