Hi DG,
I checked out the setGridLinesVisible() method, but it's only showing horizontal grid lines, not vertical. Here's the full description of my problem:
I'm generating a PNG image to display on a JSP. I've got a maximum image width limit of 420 pixels. When I query for long intervals (for example: from 01/15/2002 01:00 to 01/23/2002 23:00), JFreeChart produces the graph, but the X-Axis displays only one label (in my case, it's 01/21/2002). The person who is studying the generated graph has to guess the other dates, since there aren't any other X-Axis labels available. I guess this happens because of the image width limit.
Therefore, if I have vertical gridlines, this would help the user understand more precisely what is being demonstrated.
I'm not sure if I have been clear now. Please let me know so that I can solve any doubts.
Thanks in advance,
Rudra A Dixit
setGridLinesVisible() problem
RE: setGridLinesVisible() problem
Hi Rudra,
I think what is happening is your date axis is (auto) selecting a tick unit of 1 week, because it doesn't have room to display the labels for 1-day tick units (the next smallest size). You could try a couple of things:
(1) HorizontalDateAxis.setVerticalTickLabels(true). When the labels are vertical, you can fit more of them in (but you get less plotting space).
(2) Edit the code in DateAxis. Add a new entry (or several) in standardTickMagnitudes, standardTickUnits and standardTickFormats. If you add a tick unit for 2 days, between 1 and 7 days, that might solve your problem.
Otherwise you will have to wait until I get minor tick units implemented...
Regards,
DG.
I think what is happening is your date axis is (auto) selecting a tick unit of 1 week, because it doesn't have room to display the labels for 1-day tick units (the next smallest size). You could try a couple of things:
(1) HorizontalDateAxis.setVerticalTickLabels(true). When the labels are vertical, you can fit more of them in (but you get less plotting space).
(2) Edit the code in DateAxis. Add a new entry (or several) in standardTickMagnitudes, standardTickUnits and standardTickFormats. If you add a tick unit for 2 days, between 1 and 7 days, that might solve your problem.
Otherwise you will have to wait until I get minor tick units implemented...
Regards,
DG.
Re: setGridLinesVisible() problem
Hi,
Currently the method setShowGridLines() in ValueAxis does not work properly when trying to display horizontal grids from HorizontalDateAxis with the following error:
java.lang.IllegalArgumentException: null Stroke
at sun.java2d.SunGraphics2D.setStroke(SunGraphics2D.java:801)
at com.jrefinery.chart.HorizontalDateAxis.draw(HorizontalDateAxis.java, Compiled Code)
at com.jrefinery.chart.XYPlot.draw(XYPlot.java, Compiled Code)
at com.jrefinery.chart.JFreeChart.draw(JFreeChart.java, Compiled Code)
at com.jrefinery.chart.JFreeChart.createBufferedImage(JFreeChart.java:506)
at com.jrefinery.chart.ChartUtilities.writeChartAsJPEG(ChartUtilities.java:101)
Here is a fix:
There are 4 constructors for HorizontalDateAxis. The last 2 arguments are set to null by default and this is causing the issue. Replace these 2 nulls with "ValueAxis.DEFAULT_GRID_LINE_STROKE, ValueAxis.DEFAULT_GRID_LINE_PAINT". Re-compile the library and enjoy your graph.
(It took awhile to figure this out...)
-JYK
Currently the method setShowGridLines() in ValueAxis does not work properly when trying to display horizontal grids from HorizontalDateAxis with the following error:
java.lang.IllegalArgumentException: null Stroke
at sun.java2d.SunGraphics2D.setStroke(SunGraphics2D.java:801)
at com.jrefinery.chart.HorizontalDateAxis.draw(HorizontalDateAxis.java, Compiled Code)
at com.jrefinery.chart.XYPlot.draw(XYPlot.java, Compiled Code)
at com.jrefinery.chart.JFreeChart.draw(JFreeChart.java, Compiled Code)
at com.jrefinery.chart.JFreeChart.createBufferedImage(JFreeChart.java:506)
at com.jrefinery.chart.ChartUtilities.writeChartAsJPEG(ChartUtilities.java:101)
Here is a fix:
There are 4 constructors for HorizontalDateAxis. The last 2 arguments are set to null by default and this is causing the issue. Replace these 2 nulls with "ValueAxis.DEFAULT_GRID_LINE_STROKE, ValueAxis.DEFAULT_GRID_LINE_PAINT". Re-compile the library and enjoy your graph.
(It took awhile to figure this out...)
-JYK
Re: setGridLinesVisible() problem
Hi James,
Thanks for the report. It looks like I've already fixed this, but I want to be sure so can you tell me what version of JFreeChart you are using?
Regards,
Dave Gilbert
Thanks for the report. It looks like I've already fixed this, but I want to be sure so can you tell me what version of JFreeChart you are using?
Regards,
Dave Gilbert
Re: setGridLinesVisible() problem
Thanks. I think you will find it is fixed in a later version. If not, let me know and I'll look at it again.
DG.
DG.