Offscreen Imaging: X11, DISPLAY, BufferedImage

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

Re: java.awt.headless prop works

Postby kianfatt1982 » Thu Dec 15, 2005 9:12 am

RV wrote:I set this prop to disable X11 dependency. And it works fine on solaris 2.8


I am running the probalmetic codes in a solatis machine too, but can you teach me as where to set java properties ,

I got the serveletexception errot when I try to declare a feference variable of CategoryAxis objCategoryAxis = null;

below is a snippet of my codes

Code: Select all
private JFreeChart createChart(CategoryDataset categorydataset, String strProfileDesc) throws Exception{
      logger.debug("[createChart] -> Start");
      JFreeChart objFreeChart = null;
      NumberAxis objNumAxis   = null;
      CategoryPlot objCatPlot = null;
      CategoryAxis objCategoryAxis    = null;

      try{
         objFreeChart =   ChartFactory.createLineChart(strProfileDesc,"Time Series","YTM",categorydataset, PlotOrientation.VERTICAL,true,   true, false);
         objCatPlot = objFreeChart.getCategoryPlot();
         objNumAxis = (NumberAxis)objCatPlot.getRangeAxis();
         
         objFreeChart.setBackgroundPaint(Color.white);
         objNumAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
         objNumAxis.setAutoRangeIncludesZero(true);

         objNumAxis.setUpperMargin(0.05);
         objNumAxis.setLowerMargin(0.05);
         objNumAxis.setLabelAngle(1.5707963267948966D);
         logger.debug("Untill Here Ok  !!!!");
         objCategoryAxis = objCatPlot.getDomainAxis();
         objCategoryAxis.setUpperMargin(0.05);
         objCategoryAxis.setLowerMargin(0.05);
         objCategoryAxis.setTickLabelFont(new Font("SansSerif",0,6));
         
         // Set Plot Area Color
         objCatPlot.setBackgroundPaint(Color.lightGray);//new Color(238, 238, 255));
         objCatPlot.setDomainGridlinePaint(Color.white); // Vertical Grid Line
         objCatPlot.setRangeGridlinePaint(Color.white); // Horizontal Grid Line
         
         // Show Graph Grid lines
         objCatPlot.setDomainGridlinesVisible(true);
         objNumAxis.setAxisLineVisible(true);
         
         // To Get The Dot Marks On The Line
         LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)objCatPlot.getRenderer();
         lineandshaperenderer.setShapesVisible(true);
          lineandshaperenderer.setDrawOutlines(true);
         //lineandshaperenderer.setUseFillPaint(true);
         //lineandshaperenderer.setFillPaint(Color.red); 
         
         // To get value label mraks on the Dot   
         lineandshaperenderer.setItemLabelsVisible(true);
         lineandshaperenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());       
           
         // Set lable of Axis X to display vertically
         objNumAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());               
         objCategoryAxis = (CategoryAxis) objCatPlot.getDomainAxis();
         objCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
         
         logger.debug("Font = "+objCategoryAxis.getTickLabelFont());   
      }catch(Exception e){
         logger.error("[createChart]",e);
         throw e;   
      }
      return objFreeChart;
   }


I have tried to programatically set the java properties before I create a reference variable of CategoryAxis but still cant.
Plase advise ? I need to get this up and running by this week please help Iam in a crisis now....
Ting Kian Fatt
(Software Engineer)
kianfatt1982@gmail.com
kianfatt1982
 
Posts: 21
Joined: Fri Sep 30, 2005 4:00 am
Location: Malaysia

Still cant work

Postby kianfatt1982 » Fri Dec 16, 2005 3:05 am

I have posted the results of my atemp in

http://www.jfree.org/phpBB2/viewtopic.php?t=15274&postdays=0&postorder=asc&&start=15

I still fail to do it, can any one please advise me on how can I make the JfreeChart work in websphere at a Solaris enviroment
Ting Kian Fatt
(Software Engineer)
kianfatt1982@gmail.com
kianfatt1982
 
Posts: 21
Joined: Fri Sep 30, 2005 4:00 am
Location: Malaysia

remove X11 related statement

Postby jam06511 » Thu Dec 22, 2005 8:10 pm

I got this problem in Linux, too when I tested demo code. And I tried to run app. with
-Djava.awt.headless=true
and add
System.setProperty("java.awt.headless","true")
to the code, but it didn't fix the problem at all. As the java app. I created is used as background job, I don't want to show up on screen. So I delete all screen (X11) related statements as below:

JFreeChart chart = createChart();
ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
panel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(panel)

Now it works very well. I think this is best option for app. running on Linux.
jam06511
 

a solution, hope can help you

Postby xuezi » Tue Aug 01, 2006 4:48 am

I fixed the problem by jam06511's solution. So thank you very much jam06511. I share my experience here with you and hope that I could help you :) .
I only wanted to create an image to show in HTML, I did not need ApplicationFrame at all. so I run the program org.jfree.chart.demo.BarChartDemo1 in Linux 9 after I had deleted all ApplicationFrame related code, it worked very well. the code after I had modified as follows:

package org.jfree.chart.demo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;

import org.jfree.chart.ChartFactory;
//import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
//import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* A simple demonstration application showing how to create a bar chart.
*/
public class BarChartDemo1 {

/**
* Creates a new demo instance.
*
* @param title the frame title.
*/

//delete extents
public BarChartDemo1(String title) {

//super(title); delete super
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
//just create a image file
org.jfree.chart.encoders.SunJPEGEncoderAdapter sjea = new org.jfree.chart.encoders.SunJPEGEncoderAdapter();
try{
sjea.encode(chart.createBufferedImage(500,270), new java.io.FileOutputStream("/root/duan/test.jpg"));
} catch(Exception e){
e.printStackTrace();
}
//ChartPanel chartPanel = new ChartPanel(chart, false);
//chartPanel.setPreferredSize(new Dimension(500, 270));
//setContentPane(chartPanel);

}

/**
* Returns a sample dataset.
*
* @return The dataset.
*/
private static CategoryDataset createDataset() {

// row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third";

// column keys...
String category1 = "Category 1";
String category2 = "Category 2";
String category3 = "Category 3";
String category4 = "Category 4";
String category5 = "Category 5";

// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(1.0, series1, category1);
dataset.addValue(4.0, series1, category2);
dataset.addValue(3.0, series1, category3);
dataset.addValue(5.0, series1, category4);
dataset.addValue(5.0, series1, category5);

dataset.addValue(5.0, series2, category1);
dataset.addValue(7.0, series2, category2);
dataset.addValue(6.0, series2, category3);
dataset.addValue(8.0, series2, category4);
dataset.addValue(4.0, series2, category5);

dataset.addValue(4.0, series3, category1);
dataset.addValue(3.0, series3, category2);
dataset.addValue(2.0, series3, category3);
dataset.addValue(3.0, series3, category4);
dataset.addValue(6.0, series3, category5);

return dataset;

}

/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private static JFreeChart createChart(CategoryDataset dataset) {

// create the chart...
JFreeChart chart = ChartFactory.createBarChart(
"Bar Chart Demo", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

// set the background color for the chart...
chart.setBackgroundPaint(Color.white);

// get a reference to the plot for further customisation...
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.white);

// set the range axis to display integers only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

// disable bar outlines...
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);

// set up gradient paints for series...
GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, new Color(0, 0, 64)
);
GradientPaint gp1 = new GradientPaint(
0.0f, 0.0f, Color.green,
0.0f, 0.0f, new Color(0, 64, 0)
);
GradientPaint gp2 = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 0.0f, new Color(64, 0, 0)
);
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
renderer.setSeriesPaint(2, gp2);

CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;

}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {

BarChartDemo1 demo = new BarChartDemo1("Bar Chart Demo");
//delete all frame related
//demo.pack();
//RefineryUtilities.centerFrameOnScreen(demo);
//demo.setVisible(true);

}

}
xuezi
 
Posts: 2
Joined: Tue Aug 01, 2006 4:29 am

Despite 'headless' Chart working on windows but not on linux

Postby prajaram » Thu Aug 10, 2006 6:56 pm

I know this issue has been beaten to death but for some of us, it is still a lingering one.

I'm NOT creating an image on a file but directly in memory and then writing it to the browser through the outputStream. This works fine on windows but on linux, initially it had some issues with Fonts. So, I had the admin look into it and he installed a new Font package on the linux server. Now, there are no error messages logged any where but the image shows up empty.

Is anyone aware of any 'font' related issues with JFreeChart deployment on linux?

Please help.

Thanks

Raj

Anonymous wrote:Hi all..
My chart woks fine on windows, but when i deply my application on linux, it does not work, but i don't get any exception or message error, or something that tell me why it isn't working...

help??

Thanks
Lucas
prajaram
 
Posts: 2
Joined: Thu Apr 20, 2006 6:01 pm

Postby javiervigil » Tue Sep 05, 2006 5:20 pm

Hi
i can't execute correctly muy charts under solaris 9, i have already set the system property java.awt.headless = true but it doesen't work

existe anoder solution?

i'm using Sun 9 and websphere 5.1

pleas help me!!!

Javier
javiervigil
 
Posts: 1
Joined: Tue Sep 05, 2006 5:17 pm

Re:can't execute correctly muy charts under solaris 9

Postby prajaram » Wed Sep 13, 2006 4:33 pm

javiervigil,

Without knowing the details of the problem it is not possible to suggest a solution. However, I can tell you how my issue got resolved. I merely upgraded to the latest version of the JDK/JRE (the server is a hosted one) and the problem just vanished.

Not sure if this is helpful but something to consider.

Thanks

Raj
prajaram
 
Posts: 2
Joined: Thu Apr 20, 2006 6:01 pm

Postby Eltar » Fri Sep 22, 2006 1:35 am

The property java.awt.headless does not exist in Java 1.3 or lower.

So if you are trying to use Java 1.3 to compile or run your code, then adding the line java.awt.headless = true will make no difference.

If you wish to use this solution (and not one of the other solutions, like the virtual X servers), then you'll have to upgrade to Java 1.4.2 or higher.




My situation involved 1.3. I'm creating graphs based on some metrics I've obtained doing normal builds with CruiseControl/Ant on a project I'm working on. The codebase requires 1.3 to build, and so that's what I had been using for everything. I had to put in a newer version of java (I went with 1.5). I then passed the path to 1.5 to Ant to run the graph application and that solved it.

Moral of the story. The java.awt.headless = true requires Java 1.4.2+ in order to fix it.
Eltar
 
Posts: 1
Joined: Fri Sep 22, 2006 1:27 am

Useful info on running jfreechart under Tomcat5 "headle

Postby kab » Sat Oct 14, 2006 8:36 pm

Three things I recently discovered about running JFreeChart under Tomcat5 on CentOS 4 (a community version of RedHat Enterprise), running with Java 1.5:

a. I was able to run with the jcommon and jfreechart jars in
~tomcat5/common/lib

b. To get Tomcat to run in "headless" mode, I placed the following line in /etc/tomcat5/tomcat.conf:

wrapper.java.additional.6=-Djava.awt.headless=true

c. It's important to remove any "heavyweight" graphics calls from your code. For example (cost me some hairpulling): I left a "extends ApplicationFrame" in place with a corresponding super("Test Me"); statement. This provokes a heavyweight call. The following link provides an excellent discussion of using headless mode:

http://java.sun.com/developer/technical ... p/headless
kab
 
Posts: 3
Joined: Wed Feb 23, 2005 1:58 am
Location: Cambridge, MA, USA

Jfreechart Info required

Postby heartt_thief » Thu Nov 01, 2007 9:40 am

Can anyone plz help me out in this -------->
Requirement----->
1-> No awt Or swings
2->unix or linux environment
3-> need to have the chart output in d form of image

Can u tell me which class of jfreechart to use for price v/s time chart....

Thanx in advance.....
heartt_thief
 
Posts: 2
Joined: Thu Nov 01, 2007 9:35 am

Postby caa » Wed Nov 28, 2007 5:50 pm

You're out of luck with requirement #1. All of the java graphics operations that I know of boil down to the java.awt package.
All of the renders draw on a java.awt.Graphics2D object.
Charles Anderson
caa
 
Posts: 21
Joined: Mon Feb 14, 2005 11:28 pm

Postby john.focker » Mon Jan 14, 2008 6:26 am

Hi John, :D

Thanks for providing this excellent summary. It may become the first entry in the JFreeChart FAQ!

Regards,

J.F
john.focker
 
Posts: 1
Joined: Fri Jan 11, 2008 7:02 pm

Problem on UNIX/Solaris (no X11)

Postby shibaevv » Thu Oct 30, 2008 5:11 am

Yes, this article
java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_I_have_an_application_that_rea
helped to solve the problem with JFreeChart running (failing) on Solaris with no X11 shell active.
I have just added "-Djava.awt.headless=true" to application server start up script.
shibaevv
 
Posts: 1
Joined: Thu Oct 30, 2008 4:59 am
Location: Australia

Re: Problem on UNIX/Solaris (no X11)

Postby brianbeech » Wed Nov 26, 2008 8:38 pm

shibaevv wrote:Yes, this article
java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_I_have_an_application_that_rea
helped to solve the problem with JFreeChart running (failing) on Solaris with no X11 shell active.
I have just added "-Djava.awt.headless=true" to application server start up script.


This actually did not work for me. I added this and I then started to get a java.awt.HeadlessException. The fix for me was simple. Here was my code to begin with:

Code: Select all
public class PrintSummary extends ApplicationFrame{
   JFreeChart chart = null;


    public PrintSummary(String title, Set list, ResultData rs, String textAppender){
      super(title + " Summary");
      CategoryDataset dataset = createDataset(title, list, rs,  textAppender);
      chart = createChart(dataset);
      ChartPanel chartPanel = new ChartPanel(chart);
      chartPanel.setPreferredSize(new Dimension(800, 600));
                setContentPane(chartPanel);
   }


I removed the extends ApplicationFrame and removed the super() and the setContentPane(). Once I did this, everything worked like magic! Took forever to find out which class was messing it up, but I hope you figure yours out faster.

Stack Trace I was getting:

Code: Select all
Error generating report.
java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        at java.awt.Window.<init>(Window.java:318)
        at java.awt.Frame.<init>(Frame.java:419)
        at javax.swing.JFrame.<init>(JFrame.java:194)

brianbeech
 
Posts: 1
Joined: Wed Nov 26, 2008 8:34 pm

Postby Taqua » Wed Nov 26, 2008 9:03 pm

So why are you using a ApplicationFrame? A JFrame cannot be created in a headless environment.
Taqua
JFreeReport Project Leader
 
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm

PreviousNext

Return to JFreeChart

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 15 guests