You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Li, Jing" <ji...@roche.com> on 2011/09/20 18:06:11 UTC

JFreeChart does not display the data

Dear All,

I am working on a project that generates a lot of JFreecharts on fly and put them in a PDF report.

I wrote a preloader, loader and source, and for unknown reason, the chart only shows the coordinates, legends, etc, but NO DATA curves. See the attachment.

I feel confused, any help or suggestions will be highly appreciated.

Thanks
Jing

/**
* Created by IntelliJ IDEA. User: lij40 Date: 9/1/11 Time: 11:04 AM To change
* this template use File | Settings | File Templates.
*/
public class ChartPreloader extends AbstractImagePreloader implements
                                                           SVGConstants
{
    /** Logger instance */
    private static Log log = LogFactory.getLog(ChartPreloader.class);

    /** {@inheritDoc} */
    public ImageInfo preloadImage(String uri, Source src, ImageContext context)
            throws IOException
    {
        return (src instanceof JFreeChartSource) ?
            getImage(uri, (JFreeChartSource) src, context) : null;
    }

      private ImageInfo getImage(String uri, final JFreeChartSource src, ImageContext context)
    {
        ImageInfo info = new ImageInfo(uri, ImageLoaderFactoryOnFly.MIME_TYPE);
        ImageSize size = new ImageSize();
        size.setSizeInPixels((int)src.getWidth(), (int)src.getHeight());
        //Set the resolution to that of the FOUserAgent
        size.setResolution(context.getSourceResolution());
        size.calcSizeFromPixels();
        info.setSize(size);

        Graphics2DImagePainter painter = new Graphics2DImagePainter()
        {

            public Dimension getImageSize()
            {
                return new Dimension((int)src.getWidth(), (int)src.getHeight());
            }


            public void paint(Graphics2D g2d, Rectangle2D area)
            {
                src.getChart().draw(g2d, area, null, null);
            }
        };

        //The whole image had to be loaded to determine the image size, so keep that information
        info.getCustomObjects()
            .put(ImageInfo.ORIGINAL_IMAGE, new ImageGraphics2D(info, painter));

        return info;
}
}


public class JFreeChartSource implements Source
{
   //public static final int CHART_SIZE = 133;
    public static final int CHART_SIZE = 250;

    private String systemId;

    private final JFreeChart chart;

    private final double width;

    private final double height;


    public JFreeChartSource(String systemId, JFreeChart chart, double width, double height)
    {
        this.systemId = systemId;
        this.chart = chart;
        this.width = width;
        this.height = height;
    }


    @Override public void setSystemId(String systemId)
    {
        this.systemId = systemId;
    }


    @Override public String getSystemId()
    {
        return systemId;
    }


    public JFreeChart getChart()
    {
        return chart;
    }


    public double getWidth()
    {
        return width;
    }


    public double getHeight()
    {
        return height;
    }
}

public class ChartHandler implements ResponseGenerator
{
    @Override public boolean canHandleUriForSource(
        Query query, Properties parameters, String uri)
    {
         return uri.contains("chart");
    }

// test case generating a Sin(x) vs Cos(x) chart
    @Override public Source getSourceResponse(
        Query query, Properties parameters, String queryText)
    {
        XYSeries dataset = new XYSeries("series0");

               for (int i = -10; i < 10; i++)
               {
                   dataset.add(i, Math.cos(i / 10.0));
               }


               XYSeries series = new XYSeries("Average Weight");
               series.add(20.0, 20.0);
               series.add(40.0, 25.0);
               series.add(55.0, 50.0);
               series.add(70.0, 65.0);
               XYDataset xyDataset = new XYSeriesCollection(series);

        JFreeChart chart = ChartFactory.createXYLineChart("Sin(x) vs X", "x", "Cos(X)",
                   /*new XYSeriesCollection(dataset)*/xyDataset,
                   PlotOrientation.VERTICAL, false, false, false);

               XYPlot plot = (XYPlot) chart.getPlot();

               /*      plot.setBackgroundPaint(new Color(0, 0, 0, 100));// Color.decode("0xF5F5F5"));

                       plot.setDomainGridlinesVisible(true);
                       plot.setRangeGridlinesVisible(true);
                       plot.setRangeGridlinePaint(Color.black);
                       plot.setDomainGridlinePaint(Color.black);

               */
               plot.setNoDataMessage("No Information.");
               // change the auto tick unit selection to integer units only...
               NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
               rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
               chart.setBackgroundPaint(Color.white);
               plot.getRenderer().setSeriesToolTipGenerator(0,
                   new StandardXYToolTipGenerator("{0}: ({1}, {2})",
                       new DecimalFormat("00"), new DecimalFormat("0.00")));



        return  new JFreeChartSource(queryText,chart, 400, 400);
    }
}



________________________________
Sample disclaimer text

RE: JFreeChart does not display the data

Posted by "Li, Jing" <ji...@roche.com>.
Jeremias,

I gave up to use ImageGraphics2D, instead I finally make it work with SVGGraphics2D.  So I wrote a preloader where the JFreeChart draws the chart to a SVGGraphics2D, then create a ImageXMLDOM from it.  Everything happened in memory, works great!

Now I have another question, since there are a lot of images and charts in my report, is there any ways to compress the image in FOP to make PDF file size smaller?

Thanks for your help. Your insights are always helpful.

Best
Jing

-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Thursday, September 22, 2011 9:59 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: JFreeChart does not display the data

Hi Jing,

PDFGraphics2D is not a complete implementation of the Graphics2D interface. There are a few gaps. Maybe JFreeChart uses one of these missing features. There could also be a bug. I suggest you set a few break points in PDFGraphics2D (you'll see which methods are empty).
Another thing you can do is generate a TIFF instead of a PDF with FOP.
If the full chart is rendered to TIFF, you'll know that your own glue code really works and there is probably an incompatibility with PDFGraphics2D. If it doesn't work, it's not PDFGraphics2D.

HTH

On 21.09.2011 16:05:27 Li, Jing wrote:
> Jeremias,
> 
> I cc you, hope I can get some advice from you, since you have a lot of experience about the custom image loaders. 
> 
> My project needs create a lot of images and charts on the fly and put them in a pdf report in the end.  I took your advice last time (See "image loading callback" back in July), wrote the preloader, loader and loader factory for both BufferedImage and JFreeChart using fop 1.0. The BufferedImage one works out nicely, the images display fine, the same as what is in Swing Panel. But when I took the same approach for the charts, JFreeChart does not show the content curves, while the same code put in a Swing panel display fine.  I suspect there are bugs in fop that prevent it displaying, but could not figure how to fix it.  Your insight will be highly appreciated.
> 
> The line in xsl-fo related to it is:
>                      <fo:block>
>                         <fo:external-graphic   src="url('chart/cwf/')" content-width="300pt" />
>                     </fo:block>
> 
> Environment:  Window 7, fop 1.0, Java 6.
> 
> There is no any error message in the trace, the customer preloader and loader all gets called, everything runs fine, except when you open the generated pdf, it show the error message, and the content curve is missing. I tried to preflight the pdf, there is no error observed either.
> 
> Thanks
> Jing
> 
> 
> 
> -----Original Message-----
> From: Pascal Sancho [mailto:pascal.sancho@takoma.fr]
> Sent: Wednesday, September 21, 2011 2:50 AM
> To: fop-users@xmlgraphics.apache.org
> Subject: Re: JFreeChart does not display the data
> 
> Reading back the properties of your attached PDF, I realize that it is made with FOP 1.0 and it is buggy when reading it.
> So, I apologize for my too quick preceding answer.
> 
> Anyway, you should give further information:
>  - short XSL-FO that demonstrates the issue
>  - trace or log, if any
>  - environment, process, etc.
> 
> Le 21/09/2011 08:43, Pascal Sancho a écrit :
> > Hi Jing,
> > 
> > I suspect you ask on wrong list, no? IIUC, I see nothing to do with 
> > FOP in your question.
> > 
> > Le 20/09/2011 18:06, Li, Jing a écrit :
> >> Dear All,
> >>
> >>  
> >>
> >> I am working on a project that generates a lot of JFreecharts on 
> >> fly and put them in a PDF report.
> >> I wrote a preloader, loader and source, and for unknown reason, the 
> >> chart only shows the coordinates, legends, etc, but NO DATA curves.
> >> See the attachment.
> >> I feel confused, any help or suggestions will be highly appreciated.
> >>
> >> Thanks
> >> Jing
> > 
> 
> --
> Pascal
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: JFreeChart does not display the data

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hi Jing,

PDFGraphics2D is not a complete implementation of the Graphics2D
interface. There are a few gaps. Maybe JFreeChart uses one of these
missing features. There could also be a bug. I suggest you set a few
break points in PDFGraphics2D (you'll see which methods are empty).
Another thing you can do is generate a TIFF instead of a PDF with FOP.
If the full chart is rendered to TIFF, you'll know that your own glue
code really works and there is probably an incompatibility with
PDFGraphics2D. If it doesn't work, it's not PDFGraphics2D.

HTH

On 21.09.2011 16:05:27 Li, Jing wrote:
> Jeremias,
> 
> I cc you, hope I can get some advice from you, since you have a lot of experience about the custom image loaders. 
> 
> My project needs create a lot of images and charts on the fly and put them in a pdf report in the end.  I took your advice last time (See "image loading callback" back in July), wrote the preloader, loader and loader factory for both BufferedImage and JFreeChart using fop 1.0. The BufferedImage one works out nicely, the images display fine, the same as what is in Swing Panel. But when I took the same approach for the charts, JFreeChart does not show the content curves, while the same code put in a Swing panel display fine.  I suspect there are bugs in fop that prevent it displaying, but could not figure how to fix it.  Your insight will be highly appreciated.
> 
> The line in xsl-fo related to it is:
>                      <fo:block>
>                         <fo:external-graphic   src="url('chart/cwf/')" content-width="300pt" />
>                     </fo:block>
> 
> Environment:  Window 7, fop 1.0, Java 6.
> 
> There is no any error message in the trace, the customer preloader and loader all gets called, everything runs fine, except when you open the generated pdf, it show the error message, and the content curve is missing. I tried to preflight the pdf, there is no error observed either.
> 
> Thanks
> Jing
> 
> 
> 
> -----Original Message-----
> From: Pascal Sancho [mailto:pascal.sancho@takoma.fr] 
> Sent: Wednesday, September 21, 2011 2:50 AM
> To: fop-users@xmlgraphics.apache.org
> Subject: Re: JFreeChart does not display the data
> 
> Reading back the properties of your attached PDF, I realize that it is made with FOP 1.0 and it is buggy when reading it.
> So, I apologize for my too quick preceding answer.
> 
> Anyway, you should give further information:
>  - short XSL-FO that demonstrates the issue
>  - trace or log, if any
>  - environment, process, etc.
> 
> Le 21/09/2011 08:43, Pascal Sancho a écrit :
> > Hi Jing,
> > 
> > I suspect you ask on wrong list, no? IIUC, I see nothing to do with 
> > FOP in your question.
> > 
> > Le 20/09/2011 18:06, Li, Jing a écrit :
> >> Dear All,
> >>
> >>  
> >>
> >> I am working on a project that generates a lot of JFreecharts on fly 
> >> and put them in a PDF report.
> >> I wrote a preloader, loader and source, and for unknown reason, the 
> >> chart only shows the coordinates, legends, etc, but NO DATA curves. 
> >> See the attachment.
> >> I feel confused, any help or suggestions will be highly appreciated.
> >>
> >> Thanks
> >> Jing
> > 
> 
> --
> Pascal
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: JFreeChart does not display the data

Posted by "Li, Jing" <ji...@roche.com>.
Jeremias,

I cc you, hope I can get some advice from you, since you have a lot of experience about the custom image loaders. 

My project needs create a lot of images and charts on the fly and put them in a pdf report in the end.  I took your advice last time (See "image loading callback" back in July), wrote the preloader, loader and loader factory for both BufferedImage and JFreeChart using fop 1.0. The BufferedImage one works out nicely, the images display fine, the same as what is in Swing Panel. But when I took the same approach for the charts, JFreeChart does not show the content curves, while the same code put in a Swing panel display fine.  I suspect there are bugs in fop that prevent it displaying, but could not figure how to fix it.  Your insight will be highly appreciated.

The line in xsl-fo related to it is:
                     <fo:block>
                        <fo:external-graphic   src="url('chart/cwf/')" content-width="300pt" />
                    </fo:block>

Environment:  Window 7, fop 1.0, Java 6.

There is no any error message in the trace, the customer preloader and loader all gets called, everything runs fine, except when you open the generated pdf, it show the error message, and the content curve is missing. I tried to preflight the pdf, there is no error observed either.

Thanks
Jing



-----Original Message-----
From: Pascal Sancho [mailto:pascal.sancho@takoma.fr] 
Sent: Wednesday, September 21, 2011 2:50 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: JFreeChart does not display the data

Reading back the properties of your attached PDF, I realize that it is made with FOP 1.0 and it is buggy when reading it.
So, I apologize for my too quick preceding answer.

Anyway, you should give further information:
 - short XSL-FO that demonstrates the issue
 - trace or log, if any
 - environment, process, etc.

Le 21/09/2011 08:43, Pascal Sancho a écrit :
> Hi Jing,
> 
> I suspect you ask on wrong list, no? IIUC, I see nothing to do with 
> FOP in your question.
> 
> Le 20/09/2011 18:06, Li, Jing a écrit :
>> Dear All,
>>
>>  
>>
>> I am working on a project that generates a lot of JFreecharts on fly 
>> and put them in a PDF report.
>> I wrote a preloader, loader and source, and for unknown reason, the 
>> chart only shows the coordinates, legends, etc, but NO DATA curves. 
>> See the attachment.
>> I feel confused, any help or suggestions will be highly appreciated.
>>
>> Thanks
>> Jing
> 

--
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: JFreeChart does not display the data

Posted by Pascal Sancho <pa...@takoma.fr>.
Reading back the properties of your attached PDF, I realize that it is
made with FOP 1.0 and it is buggy when reading it.
So, I apologize for my too quick preceding answer.

Anyway, you should give further information:
 - short XSL-FO that demonstrates the issue
 - trace or log, if any
 - environment, process, etc.

Le 21/09/2011 08:43, Pascal Sancho a écrit :
> Hi Jing,
> 
> I suspect you ask on wrong list, no? IIUC, I see nothing to do with FOP
> in your question.
> 
> Le 20/09/2011 18:06, Li, Jing a écrit :
>> Dear All,
>>
>>  
>>
>> I am working on a project that generates a lot of JFreecharts on fly and
>> put them in a PDF report.
>> I wrote a preloader, loader and source, and for unknown reason, the
>> chart only shows the coordinates, legends, etc, but NO DATA curves. See
>> the attachment.
>> I feel confused, any help or suggestions will be highly appreciated.
>>
>> Thanks
>> Jing
> 

-- 
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: JFreeChart does not display the data

Posted by Pascal Sancho <pa...@takoma.fr>.
Hi Jing,

I suspect you ask on wrong list, no? IIUC, I see nothing to do with FOP
in your question.

Le 20/09/2011 18:06, Li, Jing a écrit :
> Dear All,
> 
>  
> 
> I am working on a project that generates a lot of JFreecharts on fly and
> put them in a PDF report.
> I wrote a preloader, loader and source, and for unknown reason, the
> chart only shows the coordinates, legends, etc, but NO DATA curves. See
> the attachment.
> I feel confused, any help or suggestions will be highly appreciated.
> 
> Thanks
> Jing

-- 
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org