I create a chart in iReports, and when I compile in Eclipse, I get the following error:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$ <----------------------------------------------------> 2. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getOldValue())); //$JR_EXPR_ID=11$ <----------------------------------------------------> 3. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$ <---------------------------------------------------->3 errors at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204) at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:240) at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:173) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448) at org.reportprotojava.protosheet.Program.main(Program.java:122)
I pass the ArrayList ProtoReport (only one now when I'm testing) to the jasper compiler. The ProtoReport class contains the ChartData strong> class , which in turn has two ArrayLists of type Double, one for the X axis and one for the Y axis.
The definitions of the ProtoReport , ChartData strong> classes and the main program are as follows (slightly abbreviated):
ProtoReport Class:
package org.reportprotojava.protosheet; import java.util.ArrayList; public class ProtoReport { private String outputFileName; private String title; private String logoLocation; private String paragraphText; private ArrayList<String> tableData; private String picLocation; private int[][] graphData; //TODO decide how to store chart data private ChartData chartData; private String path; //default constructor public ProtoReport() { // Initialize object fields outputFileName = "PrototypeReport"; title = "Prototype Report"; paragraphText = "Default text"; tableData = new ArrayList<String>(); chartData = new ChartData(); //set path to working directory path = System.getProperty("user.dir"); //default to assumed report location //(ie same folder as .jrxml and .jasper files) logoLocation = path + "\\reports\\logo.jpg"; picLocation = path + "\\reports\\pic.jpg"; }
ChartData strong> Class:
package org.reportprotojava.protosheet; import java.util.ArrayList; public class ChartData { private ArrayList<Double> xAxis; private ArrayList<Double> yAxis;
Main program
public class Program {
I searched for the problem and came up with this and this , and read the datasource section on jasper sourceforge , but none of them helped solve the problem, and I made sure I used
new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})
in my diagram data source expression (and updated it when changing field names), and the fields are set to List type in iReport properties.
Here is my .jrxml
<?xml version="1.0" encoding="UTF-8"?> <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="ReportPrototype.jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43" uuid="10825c57-f953-4166-bf03-8ecabe8a8f47"> <property name="ireport.zoom" value="0.75"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="232"/> <subDataset name="ChartData" uuid="fc9ec0af-3e1a-40a7-8eb4-9ad30a266dee"> <field name="chartData.xAxis" class="java.lang.String"/> </subDataset> <queryString language="SQL"> <![CDATA[]]> </queryString> <field name="title" class="java.lang.String"/> <field name="logoLocation" class="java.lang.String"/> <field name="picLocation" class="java.lang.String"/> <field name="chartData.xAxis" class="java.lang.String"/> <detail> <band height="740" splitType="Stretch"> <textField isStretchWithOverflow="true" pattern=""> <reportElement uuid="519c6bb5-72f9-4c25-8e91-47865ae0c9df" mode="Opaque" x="39" y="75" width="378" height="45" forecolor="#000099"/> <textElement textAlignment="Center" verticalAlignment="Middle" markup="html"> <font size="26"/> </textElement> <textFieldExpression><![CDATA[$F{title}]]></textFieldExpression> </textField> <image onErrorType="Icon"> <reportElement uuid="3759a707-32a4-49ef-a9c6-b0ad7136f738" x="216" y="264" width="279" height="246"/> <imageExpression><![CDATA[$F{picLocation}]]></imageExpression> </image> <image onErrorType="Icon"> <reportElement uuid="f989f871-32ea-4f13-ae3f-3f487cde76dd" x="295" y="0" width="200" height="42"/> <imageExpression><![CDATA[$F{logoLocation}]]></imageExpression> </image> <xyLineChart> <chart> <reportElement uuid="ae87fc13-b92e-4a2a-b218-d395343f6028" x="0" y="537" width="495" height="203"/> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <xyDataset> <dataset> <datasetRun subDataset="ChartData" uuid="de7fb84d-17ea-4e5e-82bf-2015e72e4982"> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]></dataSourceExpression> </datasetRun> </dataset> </xyDataset> <linePlot> <plot/> </linePlot> </xyLineChart> </band> </detail> <pageFooter> <band height="16"> <break> <reportElement uuid="0d30dea4-a6af-4e41-b7be-c288f3188dbf" x="0" y="11" width="100" height="1"/> </break> </band> </pageFooter>
In iReports, I tried:
-Create and name ProtoReport.ChartData.xAxis and ProtoReport.ChartData.yAxis in the Fields field and fields in the ChartData source strong>. I added
-Change fields in ChartData.xAxis and ChartData.yAxis
-Change fields in chartData.xAxis and chartData.yAxis
-Applying fields to the Field field -Just using fields in ChartData - Fields
Everyone gives me an error. Any ideas what I'm doing wrong?
Additional questions:
-As it stands, my chart is likely to lead only to xAxis data points. How can I use the contents of one ArrayList for the X axis and another for the Y axis? those. xAxis and yAxis fields in the ChartData strong> object .
-Used randomData () method, which was declared earlier by main , until it is declared static , why is this?
Edit
To clarify my question: how can I name my fields, set up data sources and set up my data sets to solve this problem?
I follow the guidance provided in the comments (sorry for the non-hyperlink, as a new user, I already used all my hyperlinks) and making changes to my needs, but its data structure is simpler than mine and I would like to know how to work with more complex objects and datasets in jasper reports.