Estoy usando Jaspersoft Studio 6.2. para imprimir gráficas desde un List de Clases y me da este error:
Error evaluating expression for source text: $F{answers}
Esta es la clase que representa los datos para un gráfico:
public class GraphicP {// Gráfico de tipo PERSONAL
String area;
String question;
String[] options;
String[] answers;
Float[] score; // size: options.size X answers.size
...
(getters and setters)
...
}
Aquí un ejemplo sencillo del List con un sólo GraphicP:
List<GraphicP> listGraphics = new ArrayList<>();
GraphicP g = new GraphicP();
g.setArea(new String("Area"));
g.setQuestion(new String("pregunta"));
String[] options = new String[4];
options[0] = new String("A");
options[1] = new String("B");
options[2] = new String("C");
options[3] = new String("D");
g.setOptions(options);
String[] answers = new String[4];
answers[0] = new String("a1");
answers[1] = new String("a2");
answers[2] = new String("a3");
answers[3] = new String("a4");
g.setAnswers(answers);
Float[] scores = new Float[4];
scores[0] = new Float(10);
scores[1] = new Float(20);
scores[2] = new Float(30);
scores[3] = new Float(40);
g.setScore(scores);
listGraphics.add(g);
En este procedimiento cargo los datos en el Map para el report:
private void loadData(Map<String, Object> paramsMap, List<GraphicP> listG) {
for (GraphicP g : listG) {
List<Map<String, ?>> lineChartData = new ArrayList<Map<String, ?>>();
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("area", g.getArea());
dataMap.put("question", g.getQuestion());
dataMap.put("options", g.getOptions());
dataMap.put("answers", g.getAnswers());
dataMap.put("score", g.getScore());
lineChartData.add(dataMap);
JRMapCollectionDataSource datasource = new JRMapCollectionDataSource(lineChartData);
paramsMap.put("datasource", datasource);
}
}
Y aquí mi jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-03-25T11:15:38 -->
<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="workingEnviromentReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="89d0dab9-3d92-4e67-a86f-647d6ca9a2fe">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<template><![CDATA["styleTemplate.jrtx"]]></template>
<subDataset name="Dataset - Graphic" uuid="76111e37-0e31-48b1-946e-f28826341cc7">
<queryString><![CDATA[]]></queryString>
<field name="options" class="java.lang.String"/>
<field name="answers" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription></field>
<field name="scores" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<subDataset name="Dataset - GraphicQ" uuid="47826e0e-f281-4ec1-a750-1eb80642aa70">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="answers" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="scores" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<parameter name="datasource" class="net.sf.jasperreports.engine.data.JRMapCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</title>
<pageHeader>
<band height="100" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</pageHeader>
<columnHeader>
<band height="151" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="75" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="298" splitType="Stretch">
<barChart>
<chart evaluationTime="Report">
<reportElement x="53" y="45" width="427" height="200" uuid="1df4a571-d29d-4621-874b-f8f70bffd81f"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="Dataset - Graphic" uuid="ec923e15-0b52-48bd-9cc7-3ee7912ea3a7">
<dataSourceExpression><![CDATA[$P{datasource}]]></dataSourceExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{answers}]]></seriesExpression>
<categoryExpression><![CDATA[$F{options}]]></categoryExpression>
<valueExpression><![CDATA[$F{scores}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</barPlot>
</barChart>
</band>
</summary>
</jasperReport>
Gracias por tu tiempo!!