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" );
}