Problem porting JFreeChart from Windows to Unix

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
FBueckert
Posts: 5
Joined: Thu Jul 20, 2006 5:58 pm

Problem porting JFreeChart from Windows to Unix

Post by FBueckert » Mon Jul 31, 2006 8:52 pm

Well, I've read the FAQ about this, and I'm not getting any of the errors that are covered there. No ClassDefNotFound error, no X11 error, none of that. I've tried setting headless in all three different places. No dice.

So any other things I should try? I just can't seem to get it working. I get absolutely no error in my catalina log. It just fails silently.

If it helps, I don't have direct access to the Unix server, and it's running the korn shell or ksh. Not sure if they are one and the same or not.

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Wed Aug 02, 2006 12:41 pm

Perhaps a few more details would be handy...

If you do not have access to the server...
how does the code get run on it (is there some web based programme that uploads it for you)?

When you say it is running on the korn shell...
do you have the command line that is run?
is it a shell script that you could post?

FBueckert
Posts: 5
Joined: Thu Jul 20, 2006 5:58 pm

Post by FBueckert » Wed Aug 02, 2006 2:24 pm

Well, to get it uploaded to the server, I dump my WAR file onto a network drive, and let the server admin know there's a new build. He puts it up, and lets me know.

So, there's nothing I know of the server to help you. Sorry.

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Wed Aug 02, 2006 2:34 pm

This is porbably going to be a list of all the stuff you have already tried, but here goes a debugging list...

you are deploying as a war (tomcat) - I trust that you have tested on a local machine and it works as expected...

Are you sure that your war file is getting deployed correctly? Some versions of Tomcat don't always deploy as expected.

If you can see the catalina.out files you should be able to put in debugging messages either through System.out.prinltn() or log4j ...

How do you know that it is not working? i.e. Are you outputting as an applet, image file?
Are their permissions problems?

FBueckert
Posts: 5
Joined: Thu Jul 20, 2006 5:58 pm

Post by FBueckert » Wed Aug 02, 2006 2:54 pm

Yes, tried it on my local machine. It's Windows, and it works just fine.

My WAR file is getting deployed correctly, because every other function works except the JFreeChart.

After trying to display the chart, I check the catalina log file, and it displays nothing out of the ordinary. No error message, no nothing. It just comes up as an undisplayable image.

I'm outputting as a BufferedImage. Here's my code:
This is part of the Struts action class that populates the JFreeChart object.

Code: Select all

      //  Create the chart object
      CategoryAxis categoryAxis = new CategoryAxis("");
      ValueAxis valueAxis = new NumberAxis("Number of Calls");
      CategoryToolTipGenerator ttg = new StandardCategoryToolTipGenerator("{2}", NumberFormat.getInstance());
      BarRenderer renderer = new BarRenderer();
      renderer.setToolTipGenerator(ttg);
      Plot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
      CategoryPlot tempme = (CategoryPlot) plot;
      // set the range axis to display integers only...
      final NumberAxis rangeAxis = (NumberAxis) tempme.getRangeAxis();
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      plot = (Plot) tempme;
      boolean legend = false;
      if (list.size() > 1) {
        legend = true;
        CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.CENTER, TextBlockAnchor.BOTTOM_CENTER, TextAnchor.TOP_CENTER, Math.PI / 2.0, CategoryLabelWidthType.RANGE, .4f);
        CategoryLabelPositions pos = new CategoryLabelPositions(left, left, left, left);
        categoryAxis.setCategoryLabelPositions(pos);
      }
      JFreeChart chart = new JFreeChart(form.getReportName(), JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
      chart.setBackgroundPaint(java.awt.Color.white);
      //  Write the chart image to the temporary directory
      info = new ChartRenderingInfo(new StandardEntityCollection());
      // Get the default toolkit
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Dimension scrnsize = new Dimension();
      // Get the current screen size
      if (!GraphicsEnvironment.isHeadless()) {
         scrnsize = toolkit.getScreenSize();
      } else {
        scrnsize.height = 600;
        scrnsize.width = 800;
      }
      try {
        chart.createBufferedImage((scrnsize.width - 74), (scrnsize.height - 293), info);
      } catch (NullPointerException e) {
        e.printStackTrace();
      }
      if (form.isReasons()) {
        categoryAxis.setLabel("Reason Codes");
        renderer.setItemMargin(-30);
        categoryAxis.setLowerMargin(0.01d);
        categoryAxis.setUpperMargin(0.01d);
        CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.CENTER, TextBlockAnchor.CENTER, TextAnchor.TOP_LEFT, Math.PI / 2.0, CategoryLabelWidthType.RANGE, .2f);
        CategoryLabelPositions pos = new CategoryLabelPositions(left, left, left, left);
        categoryAxis.setCategoryLabelPositions(pos);
      }
      request.getSession().setAttribute("chart", chart);
    } catch (Exception e) {
      System.out.println("Exception - " + e.toString());
      e.printStackTrace(System.out);
    }
    form.setInfo(info);
And the JSP that displays it:

Code: Select all

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ page import = "java.io.PrintWriter" %>
<%@ page import = "java.util.Date" %>
<%@ page import = "org.jfree.chart.ChartUtilities" %>
<%@ page import = "java.io.ByteArrayOutputStream" %>
<%@ page import = "javax.imageio.ImageIO" %>
<%@ page session = "true" %>
<a href="/segue/index.do" class="black">Home</a> | <a href="/segue/itt/Report.do?task=generateCallReport" class="black">ITT Call Report</a>
<bean:define id="info" type="org.jfree.chart.ChartRenderingInfo" name="graphForm" property="info" />
<%
  String imageMap = ChartUtilities.getImageMap("imap", (org.jfree.chart.ChartRenderingInfo) pageContext.getAttribute("info"));
%>
<html:html>
<%= imageMap %>
<br /><img src="chartviewer" alt="Generated Graph" usemap="#imap" border="0" />
</html:html>
And, the ChartViewer class:

Code: Select all

package mb.edu.segue.itt.utility;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import org.jfree.chart.JFreeChart;
import java.awt.image.BufferedImage;
import com.keypoint.PngEncoder;
import java.awt.Toolkit;
import java.awt.GraphicsEnvironment;
import java.awt.Dimension;

public class ChartViewer extends HttpServlet
{
   public void doGet( HttpServletRequest request, HttpServletResponse response )
      throws ServletException, IOException
   {
      // get the chart from storage
      JFreeChart  chart = (JFreeChart) request.getSession().getAttribute("chart");
      // set the content type so the browser can see this as it is
      response.setContentType( "image/png" );
      // Get the default toolkit
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Dimension scrnsize = new Dimension();
      // Get the current screen size
      if (!GraphicsEnvironment.isHeadless()) {
         scrnsize = toolkit.getScreenSize();
      } else {
        scrnsize.height = 600;
        scrnsize.width = 800;
      }
      // send the picture
      BufferedImage buf = chart.createBufferedImage((scrnsize.width - 74), (scrnsize.height - 293), null);
      PngEncoder encoder = new PngEncoder( buf, false, 0, 9 );
      response.getOutputStream().write( encoder.pngEncode() );
   }
}
I realize that's alot of code. Thank you for your help, oacis. I appreciate it.

Locked