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

0

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 }
 ]
}

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>

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>

berlin.brown's picture
Joined: Feb 12 2019 - 10:18am
Last seen: 1 month 1 week ago

The answer below worked, strange, I removed the "Data" from the top section.

berlin.brown - 1 month 2 weeks ago

1 Answer:

0

Was able to display the chart after following changes.

Changed the data as below:

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

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>

hozawa's picture
42148
Joined: Apr 24 2010 - 4:31pm
Last seen: 14 hours 21 min ago
Feedback