Hitachi Vantara Pentaho Community Forums
Results 1 to 13 of 13

Thread: Chart not displaying in HTML report

  1. #1

    Default Chart not displaying in HTML report

    Hi,

    I have designed the reports using Pentaho report designer and integrated it in to java web application using the Pentaho java API.

    The report contain only one simple bar chart. For some reason the chart is not displaying in html page but I am able to see the chart in pdf and other export options. I am also able to see the chart when the report is being exported to HTML from report designer.

    I have checked all threads on this issue but no thread is helpful to me.

    Please help me on this issue as I am running out of time.

    Note: It has nothing to do with Pentaho BI server.

    Thanks in advance
    Aditya

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    You are probably using the stream-html export. A single stream of HTML code cannot contain images, as in HTML images are loaded via separate requests to the server. Use (for instance) the directory-html export, save your generated HTML (and with it all the CSS and image files) into a directory on the server and then serve that to the user.

    You can provide a alternateive URLRewriter so that links in the generated HTML document get forwarded to your servlet that actually ships the content to the user.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  3. #3

    Default

    Hi Taqua,

    Thanks for replying.

    Yes, I am using stream-html export. The code is,

    HtmlReportUtil.createStreamHTML(report, outputStream);

    I have tried your approach and unfortunately it does not work. The problem is with png image and styles links in HTML document. The links are not absolute. They are just the png and css files name.

    I also have seen the generated HTML report source code from BI server and Pentaho use following URL in img tag to get chart image,

    Ex:
    http://localhost:8080/pentaho/getIma...0362159859.png

    Could you please explain how do you achieve it. Do I have to include GetImage servlet?

    Thanks
    Aditya

  4. #4
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    You have to include *some* servlet that serves the report, yes. There is nothing special about the GetImage-servlet - it just looks for the image in the temp directory and ships that to the user when asked for it.

    As written above, you can influence the URL for CSS files and images by setting a URLRewriter. As you are not afraid to look into the platform code, look for the PentahoURLRewriter.

    http://source.pentaho.org/viewvc/svn...81&view=markup

    You can basically copy that class, and as pattern give it your servlet's URL. Inside Pentaho, the message-format pattern is something like

    "http://localhost:8080/pentaho/GetContent?name={0}"

    Tune it so that it points to your image-serving servlet.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  5. #5
    Join Date
    Mar 2009
    Posts
    137

    Default

    Hi,

    thanks for the information so far... I have almost the same problem...

    Well mine is a little easier I hope... I have images in my report, but I know that all those images are stored on the server (and are available through a URL http://localhost...).

    I would just like to create a stream HTML but instead of replacing all images with &nbsp as it is done right now by the output I would like to place the "real" URL... is there a way to do this with... I mean I don't need any images copied somewhere, because there are already stored and available at the server...

    HtmlReportUtil.createStreamHTML(report, outputStream);

    cause all the other stuff looks so freaky to me... is there a way to tell this createStreamHTML to keep the images and just replace the filesystem path with the URL?

    Thanks!
    Last edited by Jogilein; 05-26-2010 at 03:11 PM.

  6. #6
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Look at the source of HtmlReportUtil and copy it into your own apply a suitable URLRewriter to the HTMLPrinter instance you are using in that code.

    The HtmlReportUtil and similar classes are there to make the standard cases easy to handle, they are not extensible as this would spoil the ease-of-use.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  7. #7
    Join Date
    Mar 2009
    Posts
    137

    Default

    Thanks!

    I'm on it trying to figure out how it works... this part of the reporting engine is not as good documented as the other parts ... but well what is source code good for ...
    I'll come back when I have further information/questions

    Thanks so far!

  8. #8
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Also: There is Will Gorman's excellent book about "Pentaho Reporting 3.5 for Java Developers" which covers the exporter API in depth.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  9. #9
    Join Date
    Mar 2009
    Posts
    137

    Default

    So I got another question

    I added my own URLRewriter... but it looks like that this rewriter is never called (at least not the methods I implemented)...

    I also found this older post:
    http://forums.pentaho.org/showthread.php?t=74815

    Do I have to override the printer and not the URLRewriter? When is the later one called/used?

    Thanks!

  10. #10
    Join Date
    Mar 2009
    Posts
    137

    Default

    I implemented my own Printer and its working as shown by groucho
    http://forums.pentaho.org/showthread.php?t=74815


    Just two more questions if those are allowed:

    1.) How can I get the path of a PUC plug-in on the server... the full path?
    /home/jogilein/server/solution/system/myplugin

    2.) How can I get the URL to my plugin, used by the user to access the page?
    http://test.company.com:8080/content/myplugin

    Thanks in advance for the information!

  11. #11
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    The override should not be needed. Have a look at the platform-plugin code to see the correct way of setting the URL rewriter.

    1) Probably via getting the Servlet-Context and then resolving a URL. Then try to make sense out of the URL. The servlet-standard does not grant that information easily as it does not make the assumption that you have a filesystem to start with.

    2) The best is to use one of the helper methods of hte platform. Have a look at the PentahoReportEnvironment class for the details. THere is no automagic way as not all application servers report that URL correctly or in a reliable fashion.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  12. #12

    Default

    Hi,

    Thanks Taqua for pointing to Pentaho reporting plugin code. I have resolved my issue.

    Here is the solution,

    1. Implement the URLRewriter class. I am attaching the copy of it. You can copy thisclass, and as pattern give it your servlet's URL. Inside web application, the message-format pattern is something like
    "http://localhost:8080/<web-app-context-path>/getImage?name={0}"

    2. Add a servlet for handling the above pattern. In this way the images and stylesheets are processed

    3. Add the following lines of code instead of 'HtmlReportUtil.createStreamHtml()'

    getResponse().setHeader("Content-Disposition", "inline; filename=\"" + getReportName() + todaySdf.format(todayDate) + ".html" + "\"");
    getResponse().setHeader("Content-Description", getReportName());
    getResponse().setHeader("Pragma", "no-cache");
    getResponse().setHeader("Cache-Control", "no-cache");
    getResponse().setDateHeader("Expires", 0);
    File dataDirectory = new File(System.getProperty("java.io.tmpdir"));
    System.out.println("Temp directory for HTML Report : " + System.getProperty("java.io.tmpdir"));
    if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
    dataDirectory = dataDirectory.getParentFile();
    if (dataDirectory.isDirectory() == false) {
    throw new ReportProcessingException("Dead " + dataDirectory.getPath());
    }
    } else if (dataDirectory.exists() == false) {
    dataDirectory.mkdirs();
    }

    final FileRepository dataRepository = new FileRepository(dataDirectory);
    dataLocation = dataRepository.getRoot();
    dataNameGenerator = new DefaultNameGenerator(dataLocation);
    String appUrl = getRequest().getRequestURL().toString();
    String contextPath = getRequest().getContextPath();
    appUrl = appUrl.substring(0, appUrl.indexOf(contextPath));
    appUrl = appUrl + contextPath;
    rewriter = new HtmlURLRewriter(appUrl + "/getImage?image={0}", false);

    final StreamRepository targetRepository = new StreamRepository(null, outputStream, getReportName());
    final ContentLocation targetRoot = targetRepository.getRoot();

    final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(getReport().getConfiguration());
    final HtmlPrinter printer = new AllItemsHtmlPrinter(getReport().getResourceManager());
    printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, "index", "html"));
    printer.setDataWriter(dataLocation, dataNameGenerator);
    printer.setUrlRewriter(rewriter);
    outputProcessor.setPrinter(printer);

    final StreamReportProcessor sp = new StreamReportProcessor(getReport(), outputProcessor);
    sp.processReport();
    sp.close();

    outputStream.flush();
    outputStream.close();

    Now when you export the report as HTML, these code will execute and give you index.html file with application URLs for resource files such as image, stylesheets.

    Thanks
    Aditya
    Attached Files Attached Files

  13. #13
    Join Date
    Oct 2014
    Posts
    1

    Default Great it works

    Quote Originally Posted by aditya.future View Post
    Hi,

    Thanks Taqua for pointing to Pentaho reporting plugin code. I have resolved my issue.

    Here is the solution,

    1. Implement the URLRewriter class. I am attaching the copy of it. You can copy thisclass, and as pattern give it your servlet's URL. Inside web application, the message-format pattern is something like
    "http://localhost:8080/<web-app-context-path>/getImage?name={0}"

    2. Add a servlet for handling the above pattern. In this way the images and stylesheets are processed

    3. Add the following lines of code instead of 'HtmlReportUtil.createStreamHtml()'

    getResponse().setHeader("Content-Disposition", "inline; filename=\"" + getReportName() + todaySdf.format(todayDate) + ".html" + "\"");
    getResponse().setHeader("Content-Description", getReportName());
    getResponse().setHeader("Pragma", "no-cache");
    getResponse().setHeader("Cache-Control", "no-cache");
    getResponse().setDateHeader("Expires", 0);
    File dataDirectory = new File(System.getProperty("java.io.tmpdir"));
    System.out.println("Temp directory for HTML Report : " + System.getProperty("java.io.tmpdir"));
    if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
    dataDirectory = dataDirectory.getParentFile();
    if (dataDirectory.isDirectory() == false) {
    throw new ReportProcessingException("Dead " + dataDirectory.getPath());
    }
    } else if (dataDirectory.exists() == false) {
    dataDirectory.mkdirs();
    }

    final FileRepository dataRepository = new FileRepository(dataDirectory);
    dataLocation = dataRepository.getRoot();
    dataNameGenerator = new DefaultNameGenerator(dataLocation);
    String appUrl = getRequest().getRequestURL().toString();
    String contextPath = getRequest().getContextPath();
    appUrl = appUrl.substring(0, appUrl.indexOf(contextPath));
    appUrl = appUrl + contextPath;
    rewriter = new HtmlURLRewriter(appUrl + "/getImage?image={0}", false);

    final StreamRepository targetRepository = new StreamRepository(null, outputStream, getReportName());
    final ContentLocation targetRoot = targetRepository.getRoot();

    final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(getReport().getConfiguration());
    final HtmlPrinter printer = new AllItemsHtmlPrinter(getReport().getResourceManager());
    printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, "index", "html"));
    printer.setDataWriter(dataLocation, dataNameGenerator);
    printer.setUrlRewriter(rewriter);
    outputProcessor.setPrinter(printer);

    final StreamReportProcessor sp = new StreamReportProcessor(getReport(), outputProcessor);
    sp.processReport();
    sp.close();

    outputStream.flush();
    outputStream.close();

    Now when you export the report as HTML, these code will execute and give you index.html file with application URLs for resource files such as image, stylesheets.

    Thanks
    Aditya
    The code worked for me.

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.