Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to Create JRXML Pie Chart Based on 3 Fields


    asimkin
    • Features: Charts, Reports Version: v6.4 Product: JasperReports® Server

    Issue Description

    Customer has a requirement to create a Pie Chart in JRXML report based on 3 dataset fields.

    They created such chart in Ad Hoc View by adding 3 columns into Rows.

    How to achieve the same result in JRXML report?

    [toc]

    Resolution

    By default, Pie Chart expects that slices are represented different values of a single column/field.

    The requirements can be implemented by converting the threee values into a data source with three records

    and sending the data source to a subdatatset.

    Please find attached example, note that is uses Groovy as language for map literals.

    Report main dataset returns 3 dummy values:

    SELECT 5 as a, 8 as b, 4 as c
    

    Subdataset "chartData" contains only a list of fields, key and vallue, without any query.

    Pie Chart's dataset uses a DataSource expression to 'convert' values into records:

    new net.sf.jasperreports.engine.data.JRMapCollectionDataSource([[key:"a",value:$F{a}],[key:"b",value:$F{b}],[key:"c",value:$F{c}]])
    

    piecharton3columns.png.a2cb0a42c44b60988bd62bcf393942dc.png

    Solution tested with TIBCO JasperReports® Server v.6.4.0


    Ref. Case 01530898

    piecharton3columns.png.894b9a757905a219ee0c23520d1edbee.png

    highchartschart_3.jrxml


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...