Hi
Could i running jfreechart with tomcat usign JDK1.4.2 in mode -Djava.awt.headless=true
Regards
Philippe
jfreechart and -Djava.awt.headless=true ?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: jfreechart and -Djava.awt.headless=true ?
Did you try? It should work fine.pcouas wrote:Could i running jfreechart with tomcat usign JDK1.4.2 in mode -Djava.awt.headless=true
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


I have tried and i have following error message
java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:149)
My sample JSP Page
<%@page contentType="text/html; charset=Big5"
import="org.jfree.chart.ChartFactory"
import="org.jfree.chart.ChartFrame"
import="org.jfree.chart.JFreeChart"
import="org.jfree.chart.plot.*"
import="org.jfree.data.general.DefaultPieDataset"
%>
<%
// create a dataset...
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Category 1", 43.2);
dataset.setValue("Category 2", 27.9);
dataset.setValue("Category 3", 79.5);
// create a chart...
JFreeChart chart = ChartFactory.createPieChart(
"Sample Pie Chart",
dataset,
true, // legend?
true, // tooltips?
false // URLs?
);
// create and display a frame...
ChartFrame frame = new ChartFrame("First", chart);
frame.pack();
frame.setVisible(true);
%>
java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:149)
My sample JSP Page
<%@page contentType="text/html; charset=Big5"
import="org.jfree.chart.ChartFactory"
import="org.jfree.chart.ChartFrame"
import="org.jfree.chart.JFreeChart"
import="org.jfree.chart.plot.*"
import="org.jfree.data.general.DefaultPieDataset"
%>
<%
// create a dataset...
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Category 1", 43.2);
dataset.setValue("Category 2", 27.9);
dataset.setValue("Category 3", 79.5);
// create a chart...
JFreeChart chart = ChartFactory.createPieChart(
"Sample Pie Chart",
dataset,
true, // legend?
true, // tooltips?
false // URLs?
);
// create and display a frame...
ChartFrame frame = new ChartFrame("First", chart);
frame.pack();
frame.setVisible(true);
%>
complete error message is
java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:149)
at java.awt.Window.<init>(Window.java:300)
at java.awt.Frame.<init>(Frame.java:427)
at javax.swing.JFrame.<init>(JFrame.java:219)
at org.jfree.chart.ChartFrame.<init>(ChartFrame.java:78)
at org.jfree.chart.ChartFrame.<init>(ChartFrame.java:66)
at org.apache.jsp.jsp02_jsp._jspService(jsp02_jsp.java:64)
java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:149)
at java.awt.Window.<init>(Window.java:300)
at java.awt.Frame.<init>(Frame.java:427)
at javax.swing.JFrame.<init>(JFrame.java:219)
at org.jfree.chart.ChartFrame.<init>(ChartFrame.java:78)
at org.jfree.chart.ChartFrame.<init>(ChartFrame.java:66)
at org.apache.jsp.jsp02_jsp._jspService(jsp02_jsp.java:64)
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
ChartFrame is a subclass of JFrame - you don't want to be creating instances of Swing components in your server-side application.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Creating a frame on a server? Are you sure that you are currently writing a Web-Application?
Or is this some sort of remote control for the Web-Server admin - the users somewhere in the world open up new Frames on the server and the admin has to close them as fast as possible
Seriously: Web-Applications cannot have a Swing-GUI. You have to create HTML (through JSP pages) and images (by encoding and streaming the chart) on the server and then you have to rely on the browser to display everything correctly. If that's new to you or you haven't read the underlying standards yet, then this is a good time to do this. Grab a book on Web-Development and learn the basics, it will save you a lot of trouble later. (Web-Development has driven many upright programmers into insanity - dont take this task too lightly).
You certainly want to stream the image data to the client so that the client's browser can display the image. 'ChartUtilities.writeChartAsPNG' may serve as a starting point here.
Have fun,
said Thomas
Or is this some sort of remote control for the Web-Server admin - the users somewhere in the world open up new Frames on the server and the admin has to close them as fast as possible

Seriously: Web-Applications cannot have a Swing-GUI. You have to create HTML (through JSP pages) and images (by encoding and streaming the chart) on the server and then you have to rely on the browser to display everything correctly. If that's new to you or you haven't read the underlying standards yet, then this is a good time to do this. Grab a book on Web-Development and learn the basics, it will save you a lot of trouble later. (Web-Development has driven many upright programmers into insanity - dont take this task too lightly).
You certainly want to stream the image data to the client so that the client's browser can display the image. 'ChartUtilities.writeChartAsPNG' may serve as a starting point here.
Have fun,
said Thomas