exception generating legend in servlet

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
garyn87048
Posts: 13
Joined: Sat Nov 29, 2003 5:38 am

exception generating legend in servlet

Post by garyn87048 » Tue Feb 03, 2004 6:31 pm

Hi -

I'm getting an execption when I ask for a legend on an x/y plot. I'm generating the graphs using the jsp-servlet example. The graphs work fine until I ask for the legend. I'm not sure what I'm doing wrong, but I'm probably requesting the legend incorrectly.

Suggestions? :?


Here is the exception:
java.lang.NullPointerException
java.awt.Font.getLineMetrics(Font.java:1621)
java.awt.FontMetrics.getLineMetrics(FontMetrics.java:396)
org.jfree.chart.StandardLegend.createDrawableLegendItem(Unknown Source)
org.jfree.chart.StandardLegend.draw(Unknown Source)
org.jfree.chart.StandardLegend.draw(Unknown Source)
org.jfree.chart.JFreeChart.draw(Unknown Source)
org.jfree.chart.JFreeChart.createBufferedImage(Unknown Source)
org.jfree.chart.ChartUtilities.writeChartAsPNG(Unknown Source)
org.jfree.chart.ChartUtilities.saveChartAsPNG(Unknown Source)
org.jfree.chart.ChartUtilities.saveChartAsPNG(Unknown Source)
org.jfree.chart.servlet.ServletUtilities.saveChartAsPNG(Unknown Source)
com.intel.f11litho.WQT.WQTGraphEngine.WQTGraph_Trend(WQTGraphEngine.java:107)
org.apache.jsp.WQTGraphIt_jsp._jspService(WQTGraphIt_jsp.java:53)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

Here is the code:

// create and populate a sample xyseries collection
XYSeries dataSeries1 = new XYSeries( null );
XYSeries dataSeries2 = new XYSeries( null );
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumIntegerDigits( 2 );
DateFormat format_in = new SimpleDateFormat ("ddMMMyyyy:hh:mm:ss");
String dateStr = "JAN2004:01:01:01";
java.util.Date date;
for( int j=1; j<6; j++ ) {
try {
date = format_in.parse( nf.format( j ) + dateStr );
}
catch( ParseException pe ) {
System.out.println( "not able to parse date" );
}
long J = j;
dataSeries1.add( date.getTime(), J );
dataSeries2.add( date.getTime(), J+2 );
}
XYSeriesCollection xyDataset = new XYSeriesCollection( );
xyDataset.addSeries( dataSeries1 );
xyDataset.addSeries( dataSeries2 );

// tool tips
SimpleDateFormat sdf = new SimpleDateFormat( "dd-MMM-yyyy" );
TimeSeriesToolTipGenerator ttg = new TimeSeriesToolTipGenerator( sdf, NumberFormat.getInstance() );

// create a chart object
ValueAxis timeAxis = new DateAxis( "" );
NumberAxis numAxis = new NumberAxis( "" );
numAxis.setAutoRangeIncludesZero( false );
StandardXYItemRenderer renderer = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, ttg );
renderer.setShapesFilled( true );

// create a chart
XYPlot plot = new XYPlot( xyDataset, timeAxis, numAxis, renderer );

// * * * * * * * dies here * * * * * * *
// dies here. if last argument is 'false', then succeeds
JFreeChart chart = new JFreeChart( "title", JFreeChart.DEFAULT_TITLE_FONT, plot, true );

chart.setBackgroundPaint( java.awt.Color.white );

ChartRenderingInfo info = new ChartRenderingInfo( new StandardEntityCollection() );
try {
filename = ServletUtilities.saveChartAsPNG( chart, 500, 300, info, session );

ChartUtilities.writeImageMap( pw, filename, info );
pw.flush();
}
catch( IOException e ) {
System.out.println( "i/o exception" );
}

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 » Wed Feb 04, 2004 11:22 am

My guess is that one of your series names is null. Can you file a bug report in the database at SourceForge? I need to fix the code so that (a) you can't set a series name to null in the first place, and (b) if it ever does happen, the code should just treat it as an empty string.
David Gilbert
JFreeChart Project Leader

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

garyn87048
Posts: 13
Joined: Sat Nov 29, 2003 5:38 am

Post by garyn87048 » Thu Feb 19, 2004 8:33 pm

David -

No bug report yet -

Sorry for the delay - I was not able to submit a bug report. Should my jfree.org account work or do I need to setup a new account on Source Forge.net?

Gary

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 » Fri Feb 20, 2004 1:55 pm

It's OK, I've changed the code already so that it will throw an exception straight away if you try to create a series with null for the series name.

You can report bugs anonymously at SourceForge, or register an account with them if you want to receive e-mail notifications about bugs you have posted.
David Gilbert
JFreeChart Project Leader

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

Locked