Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Unable to Embed charts in Report generated programmatically

  1. #1

    Post Unable to Embed charts in Report generated programmatically


    I am unable to embed charts in reports generated programmatically.

    Chart gets embedded if I load a .prpt file created using Pentaho Report Designer and create a report using that report definition.

    But I tried to generate a report defining everything programmatically and I tried to add a Chart to it as an element in Report Header but could not figure out how to cast it to an Element.


  2. #2
    Join Date
    Mar 2003


    A chart is created via a expression.

    So you first create a Element, set its type to "LegacyChartType". Then you have to add the chart-expression and the data-set collector expressions to the appropriate attributes of that element.

        AbstractChartExpression chartExpression; // create one of the chart-expression and configure it 
        AbstractCollectorFunction dataCollector; // create a suitable data-collector
        AbstractCollectorFunction dataCollector2; // if you use a line-bar-chart, create a suitable secondary data-collector
        Element e = new Element();
        e.setAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, chartExpression);
            (LegacyChartElementModule.NAMESPACE, LegacyChartElementModule.PRIMARY_DATA_COLLECTOR_FUNCTION_ATTRIBUTE,
            (LegacyChartElementModule.NAMESPACE, LegacyChartElementModule.SECONDARY_DATA_COLLECTOR_FUNCTION_ATTRIBUTE,
    Note that you do need to configure the expressions before you can use them. The report-designer's chart-editor is a thin layer over these expressions. I would recommend that you experiment with designing your chart there and then apply the same properties to your code.

    I heavily recommend that you grab a copy of Will Gorman's Book "Pentaho Reporting 3.5 for Java Developers" and read the section about charting. The book also contains the only property reference that ever has been written. Otherwise: use the source, the expressions are all Java Beans.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

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.