Jump to content
JasperReports Library 7.0 is now available ×

How to feed JSON data to the charts and what types, what about arrays?


berlin.brown
Go to solution Solved by hozawa,

Recommended Posts

I am trying to feed a simple JSON array into the chart types but I am getting an empty document when testing through studio.  How can you pass an array to a document?

 

For example:

{ "Data": [     { "x":1, "y":2 },     { "x":1, "y":3 } ]}[/code]

And then I want to pass to this chart and data:


 

    <queryString>        <![CDATA[Data]]>    </queryString>    <field name="x" class="java.lang.Double">        <property name="net.sf.jasperreports.json.field.expression" value="x"/>    </field>    <field name="y" class="java.lang.Double">        <property name="net.sf.jasperreports.json.field.expression" value="y"/>    </field><xyAreaChart>                <chart evaluationTime="Report">                    <reportElement x="40" y="20" width="200" height="200" uuid="952fc1ba-070b-4171-9007-62cfdf705e5c"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <xyDataset>                    <xySeries>                        <seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>                        <xValueExpression><![CDATA[$F{x}]]></xValueExpression>                        <yValueExpression><![CDATA[$F{y}]]></yValueExpression>                    </xySeries>                </xyDataset>[/code]

I get a response of an empty document when I try to render.

Also, is it possible to have a field of type array?

Here is the full jrxml:

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --><!-- 2019-04-08T16:36:59 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="GraphTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f981967e-6bf6-47a4-bcca-cd45fc19aab9">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="CsvGraph"/>    <queryString>        <![CDATA[Data]]>    </queryString>    <field name="x" class="java.lang.Double">        <property name="net.sf.jasperreports.json.field.expression" value="x"/>    </field>    <field name="y" class="java.lang.Double">        <property name="net.sf.jasperreports.json.field.expression" value="y"/>    </field>    <background>        <band splitType="Stretch"/>    </background>    <title>        <band height="79" splitType="Stretch"/>    </title>    <pageHeader>        <band height="49" splitType="Stretch">            <staticText>                <reportElement x="250" y="19" width="100" height="30" uuid="1bb91627-867b-4045-b582-4ef3ff30a7cc"/>                <text><![CDATA[simple Line Area Graph]]></text>            </staticText>        </band>    </pageHeader>    <columnHeader>        <band height="61" splitType="Stretch">            <staticText>                <reportElement x="250" y="19" width="100" height="30" uuid="383dbef6-0ee3-4b53-91f7-64f16f5bc745"/>                <text><![CDATA[simple Line Area Graph]]></text>            </staticText>        </band>    </columnHeader>    <detail>        <band height="398" splitType="Stretch">            <xyAreaChart>                <chart evaluationTime="Report">                    <reportElement x="40" y="20" width="200" height="200" uuid="952fc1ba-070b-4171-9007-62cfdf705e5c"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <xyDataset>                    <xySeries>                        <seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>                        <xValueExpression><![CDATA[$F{x}]]></xValueExpression>                        <yValueExpression><![CDATA[$F{y}]]></yValueExpression>                    </xySeries>                </xyDataset>                <areaPlot>                    <plot/>                    <categoryAxisFormat>                        <axisFormat/>                    </categoryAxisFormat>                    <valueAxisFormat>                        <axisFormat/>                    </valueAxisFormat>                </areaPlot>            </xyAreaChart>        </band>    </detail>    <columnFooter>        <band height="45" splitType="Stretch"/>    </columnFooter>    <pageFooter>        <band height="54" splitType="Stretch">            <staticText>                <reportElement x="250" y="19" width="100" height="30" uuid="cc183642-0d72-4347-bcea-e66f0a6e1a72"/>                <text><![CDATA[simple Line Area Graph]]></text>            </staticText>        </band>    </pageFooter>    <summary>        <band height="42" splitType="Stretch"/>    </summary></jasperReport>[/code]

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution

Was able to display the chart after following changes.

Changed the data as below:

{"Data": [     { "x":1, "y":2 },     { "x":2, "y":3 } ]}[/code]

And moved the chart to ehe Summary band and deleted all other bands to make it clearer.

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="GraphTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f981967e-6bf6-47a4-bcca-cd45fc19aab9">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSON Test2"/>    <queryString language="JSON">        <![CDATA[Data]]>    </queryString>    <field name="x" class="java.lang.Double">        <fieldDescription><![CDATA[x]]></fieldDescription>    </field>    <field name="y" class="java.lang.Double">        <fieldDescription><![CDATA[y]]></fieldDescription>    </field>    <summary>        <band height="320" splitType="Stretch">            <xyAreaChart>                <chart evaluationTime="Report">                    <reportElement x="0" y="0" width="420" height="320" uuid="183bf92e-8769-4a46-be19-912b43eb7991"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <xyDataset>                    <xySeries>                        <seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>                        <xValueExpression><![CDATA[$F{x}]]></xValueExpression>                        <yValueExpression><![CDATA[$F{y}]]></yValueExpression>                    </xySeries>                </xyDataset>                <areaPlot>                    <plot/>                    <categoryAxisFormat>                        <axisFormat/>                    </categoryAxisFormat>                    <valueAxisFormat>                        <axisFormat/>                    </valueAxisFormat>                </areaPlot>            </xyAreaChart>        </band>    </summary></jasperReport>[/code]

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...