我正在使用Jaspersoft Studio 6.2。从类列表中打印图表并得到此错误:
Error evaluating expression for source text: $F{answers}
这是表示图表数据的类:
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)
...
}
这是一个仅包含一个GraphicP的List的简单示例:
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);
在此代码中,将显示报告地图上数据的加载:
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);
}
}
这里是我的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>
提前感谢您的时间!!