about timechart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dennislee
Posts: 13
Joined: Mon Feb 23, 2004 3:02 am
Location: beijing, china

about timechart

Post by dennislee » Fri Feb 27, 2004 3:11 am

hi everyone

i encounted a problem, it may be a bug of jfreechart :-(
my environment list:
os windows2000
ejb(jboss server) + jsp(tomcat server)

i create a jfreechart that is a pie chart ,by ejb remote inteface poss it to jsp ,then display on IE
it is ok!
but when i create a jfreechart that is a TimeSeriesDemo chart ,by ejb remote inteface poss it
to jsb ,it is fail!:-(
following is febug information

public void piechart(OutputStream x) {
JFreeChart mychart = null;

java.io.File file = new java.io.File("c:\\c.jpg");
mychart = chart();

try {
org.jfree.chart.ChartUtilities.saveChartAsJPEG(file, mychart, 800, 600);

}catch (Exception e) {
e.printStackTrace();
}
}

java.lang.NullPointerException at org.jfree.chart.axis.DateAxis.previousStandardDate(Unknown Source) at org.jfree.chart.axis.DateAxis.nextStandardDate(Unknown Source) at org.jfree.chart.axis.DateAxis.calculateLowestVisibleTickValue(Unknown Source) at org.jfree.chart.axis.DateAxis.refreshTicksHorizontal(Unknown Source) at org.jfree.chart.axis.DateAxis.refreshTicks(Unknown Source) at org.jfree.chart.axis.ValueAxis.reserveSpace(Unknown Source) at org.jfree.chart.plot.XYPlot.calculateDomainAxisSpace(Unknown Source) at org.jfree.chart.plot.XYPlot.calculateAxisSpace(Unknown Source) at org.jfree.chart.plot.XYPlot.draw(Unknown Source) at org.jfree.chart.JFreeChart.draw(Unknown Source) at org.jfree.chart.JFreeChart.createBufferedImage(Unknown Source) at org.jfree.chart.ChartUtilities.writeChartAsJPEG(Unknown Source) at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Unknown Source) at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Unknown Source) at jspchart.Jsp1Bean.piechart(Jsp1Bean.java:70) at org.apache.jsp.jsp1$jsp._jspService(jsp1$jsp.java:100) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027) at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125) at java.lang.Thread.run(Thread.java:534)


why???
please help me

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 27, 2004 11:39 am

Certainly a bug. Is there any chance you can get the same chart into a standalone app (like the ones in org.jfree.chart.demo) and reproduce the problem? Then send me the code and I'll be able to find the bug really quickly.

Another thing to try is the latest code from CVS - there have been some bugs fixed in the DateAxis class relating to the tick generation, although I'm not sure they would cause the symptoms you are seeing.

Unless of course this is all related to the EJB remote interface (about which I know very little). Does this mean the chart is being serialized / deserialized? The chances of triggering a bug in that process are *much* higher. There are a number of JUnit tests aimed at testing the serialization of JFreeChart classes, but the coverage is not even close to complete.
David Gilbert
JFreeChart Project Leader

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

r0main

anything in the dev pipeline about that fonctionnality ?

Post by r0main » Fri Feb 27, 2004 11:55 am

anything in the dev pipeline about that fonctionnality ?

r0main

sorry, wrong thread... :-)

Post by r0main » Fri Feb 27, 2004 11:57 am

sorry, wrong thread... :-)

dennislee
Posts: 13
Joined: Mon Feb 23, 2004 3:02 am
Location: beijing, china

The time chart

Post by dennislee » Mon Mar 01, 2004 4:01 am

Hi David:
Thank you J
About EJB remote interface you said is good! In fact it is serialized and deserialized.if I code it
Into a standalone app(like the ones in org.jfree.chart.demo),it is very good!
Following is my EJB code
…………………
private DefaultPieDataset getMyPieData() {
DefaultPieDataset dataset = new DefaultPieDataset();
Dataset.setValue(“type1”, 200);
Dataset.setValue(“type2”, 200);
Dataset.setValue(“type3”, 200);
Dataset.setValue(“type4”, 200);
Return dataset;
}
/** this method is a EJB remote method that pass a jfreechart obj to JSP
public JfreeChart getMyChart() {
JfreeChart chart = null;
Chart = ChartFactory.createPie3Dchart(“my pie chart”, getMyPieData(), true, false, false);
}
above code run is very good!
But if run following code ,the error has occur!!L
……………………..
private TimeSeriesCollection getMyDateSer() {
TimeSeries series = new TimeSeries(“one”, Month.class);
Series.add(new Month(1, 2004), 500.2);
………
series.add(new Month(12. 2004), 233.3);
TimeSeriesCollection dataset = new TimeSeriesCollection();
Dataset.addSeries(series);
Return dataset;
}
/** this method is also a EJB remote method that pass a jfreechart obj to jsp */
public JfreeChart getMyTimeChart() {
return ChartFactory.createTimeSeriesChart(“time demo”, “time”, “value”, getMyDateSer(), true, true, false );
}

++++++++++++++++++++++following is my JSP code ++++++++++++++++++++++++++++
…………….
Private JfreeChart getChart() {
/** look up EJB remote obj code **************/
try{
JfreeChart chart = REMOTEMETHOD(such as xxxrmtobj). GetMyTimeChart()
ChartUtilities.saveChartAsJPEG(JSPOUTPUTSTREAM__OBJ, chart, 800, 600J,
} catch(Exception e) {|

if JfreeChart chart = REMOTEMETHOD(such as xxxrmtobj). GetMyTimeChart() change
JfreeChart chart = REMOTEMETHOD(such as xxxrmtobj). getMyPieData (); it is very good!
But if GetMyTimeChart() method hax called! The error hax occur!!!!! Why?????

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 » Mon Mar 01, 2004 6:39 pm

There is a lot of untested code in the serialization, so you are likely to run into problems like this. Just now I've found small problems with the serialization of the TimeSeriesCollection class, and am about to commit a JUnit test and fixes for these problems to CVS. When I get time (perhaps tomorrow) I'll move on to the complete time series chart and see what problems I can spot there.

The best I will be able to do is to get some basic tests to run and squash the obvious bugs. It would help a lot if you (or others) are able to keep testing this area of the code...
David Gilbert
JFreeChart Project Leader

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

dennislee
Posts: 13
Joined: Mon Feb 23, 2004 3:02 am
Location: beijing, china

about time chart

Post by dennislee » Tue Mar 02, 2004 2:41 am

Hi David

That is no problem :P

I will test code about TimeSeriesCollection, if you think the problem has be fixed! please
tell me , i will test

thank you
:wink:

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 » Tue Mar 02, 2004 11:56 am

I've fixed a couple of bugs in CVS now, but I wouldn't expect them to cause the exception you are reporting. I'm going to try to put together a demo app that can be used as a serialization/deserialization testing framework, and see what other bugs I can uncover.

I'm also interested in getting more JUnit tests written to verify that the serialization/deserialization process is working as it should be.
David Gilbert
JFreeChart Project Leader

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

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 » Tue Mar 02, 2004 12:44 pm

Here's the code I am using to test a time series chart. With 0.9.16 it fails (no exceptions are generated though) in that the axes and plot are drawn correctly, but no data is rendered. With the latest CVS code, it works as expected.

I'm not 100% confident that my test is a good simulation of the serialization process between two independent JVMs - comments are welcome:

Code: Select all

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * -----------------------
 * SerializationTest1.java
 * -----------------------
 * (C) Copyright 2004, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited).
 * Contributor(s):   -;
 *
 * $Id: DynamicDataDemo.java,v 1.7 2004/02/04 11:06:15 mungady Exp $
 *
 * Changes
 * -------
 * 02-Mar-2004 : Version 1 (DG);
 *
 */

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

import javax.swing.JButton;
import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.XYDataset;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * Based on the DynamicDataDemo class, this demo serializes and deserializes the chart
 * before displaying it - the idea is that this confirms that the serialization process
 * returns a working chart.
 *
 * @author David Gilbert
 */
public class SerializationTest1 extends ApplicationFrame implements ActionListener {

    /** The time series data. */
    private TimeSeries series;

    /** The most recent value added. */
    private double lastValue = 100.0;

    /**
     * Constructs a new demonstration application.
     *
     * @param title  the frame title.
     */
    public SerializationTest1(String title) {

        super(title);
        this.series = new TimeSeries("Random Data", Millisecond.class);
        TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
        JFreeChart chart = createChart(dataset);

        // SERIALIZE - DESERIALIZE for testing purposes
        JFreeChart deserializedChart = null;

        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(chart);
            out.close();
            chart = null;
            dataset = null;
            this.series = null;
            System.gc();

            ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
            deserializedChart = (JFreeChart) in.readObject();
            in.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        TimeSeriesCollection c = (TimeSeriesCollection) deserializedChart.getXYPlot().getDataset();
        this.series = c.getSeries(0);
        // FINISHED TEST

        ChartPanel chartPanel = new ChartPanel(deserializedChart);
        JButton button = new JButton("Add New Data Item");
        button.setActionCommand("ADD_DATA");
        button.addActionListener(this);

        JPanel content = new JPanel(new BorderLayout());
        content.add(chartPanel);
        content.add(button, BorderLayout.SOUTH);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(content);

    }

    private JFreeChart createChart(XYDataset dataset) {
        JFreeChart result = ChartFactory.createTimeSeriesChart(
            "Serialization Test 1", 
            "Time", 
            "Value",
            dataset, 
            true, 
            true, 
            false
        );
        XYPlot plot = result.getXYPlot();
        ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        axis.setFixedAutoRange(60000.0);  // 60 seconds
        return result;
    }
    
    /**
     * Handles a click on the button by adding new (random) data.
     *
     * @param e  the action event.
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("ADD_DATA")) {
            double factor = 0.90 + 0.2 * Math.random();
            this.lastValue = lastValue * factor;
            Millisecond now = new Millisecond();
            System.out.println("Now = " + now.toString());
            this.series.add(new Millisecond(), lastValue);
        }
    }

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

        SerializationTest1 demo = new SerializationTest1("Serialization Test 1");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}
David Gilbert
JFreeChart Project Leader

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

dennislee
Posts: 13
Joined: Mon Feb 23, 2004 3:02 am
Location: beijing, china

about test

Post by dennislee » Wed Mar 03, 2004 4:02 am

Hi David
I have download the latest jfreechart that jcommon-0.9.1.zip and jfreechart-0.9.16
After test but the same error still has occurred.
It is very bizarrerie. The JfreeChart Object(only by ChartFactory.createTimeSeriesChart(…) made) as the EJB Remote method result type (such as public JfreeChart myejbmethod()),when the Remote mothod has called, the result is bad(but is is no null),
But if you use ChartFactory.createPieChart3D(…), is is very good!
Your SerializationTest1.java demo is ok, now I am try use your way ,to finish my task

Because I am use EJB Server(JBoss)
My code like following
My ejb remote method result type byte[]
Public byte[] ejbmethod() {
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
ChartUtilities.writeChartAsJPEG(tmp, 100, chart, 800, 600);
Return tmp.toByteArray();
}
when I do in this way ,it is ok (Piechart is ok ,TimeSeriesChart also is ok!)

if you have free time , pleast look it againJ

thank you very much
good luck to you!
Dennis.lee 2004-03-03

Locked