Мне трудно понять, как передать данные из пользовательского источника данных JR на диаграмму, но я передаю данные в отчет, однако, когда бы я ни пытался передать их на диаграмму, они ничего не показывают. Значения, которые я пытаюсь передать, - это среднее значение, дни и SD для создания отчета о внесении изменений. Вот код ниже для класса источника данных:
package MyDataAdapt;
import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
public class GoImplementation implements JRDataSource {
public GoImplementation() {
// TODO Auto-generated constructor stub
}
/**
* For this data adapter the informations are embedded in the code
*/
private static final Integer[] lotNum = {33301141,33301143 };
private static final Integer[] level= {1,3};
private static final double[] mean= {4.49,457.04};
private static final double[] SD= {0.30,22.58};
private static final double[] CV= {6.79,4.94};
private static final Integer[] N= {54,53};
private HashMap<String, String> capitalCities = new HashMap<String, String>();
private static final double[] mean2= {3.92,465.95};
private static final double[] SD2= {0.35,31.11};
private static final double[] CV2= {9.04,6.68};
private static final Integer[] N2= {333,340};
private static final String[] department = {"GENERAL"," "};
private static final String[] instruementArray = {"ARCHITECT cI4100-I1SR"," "};
private static final String[] test = {"Human Chronic Gonadotropin (BhCG) {7K78}(mIU/mL"," "};
private static final String[] method = {"NONE"," "};
private static final String[] reagentArray = {"ABBOTT"," "};
private static final String[] month = {"January, 2015"," "};
private static final String[] shift = {"All"," "};
private static final String[] qcProduct = {"MULTICHEM IA PLUS(05P76-10)"," "};
private static final Integer[] days = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
HashMap<String, Integer> lotp = new HashMap<String, Integer>();
HashMap<String, Double> meanp = new HashMap<String, Double>();
HashMap<String, Double> sdp= new HashMap<String, Double>();
HashMap<String,Integer> dayp = new HashMap<String, Integer>();
/**
* Variable to store how much records were read
*/
private int counter = -1;
/**
* Variables to store the number of fields, and their names, in the report
*/
private HashMap<String, Integer> fieldsNumber = new HashMap<String, Integer>();
/**
* Method used to know if there are records to read.
*/
private int lastFieldsAdded = 0;
@Override
public boolean next() throws JRException {
if (counter<lotNum.length-1) {
counter++;
return true;
}
return false;
}
/**
* This method is called for every field defined in the report. So if i have 2 fields it is called 2 times for every record, and
* for each of them it must provide a value.
* The parameter can be used to understand for which field is requested, in fact it contains the name of the requested field. This
* data adapter is done with the goal of return two values, a name and an age. An easy option would be expect a field with the name
* "Name" and one with name "Age". But we can do something more flexible, in this case we will enumerate all the fields requested and
* and the first two will be assumed to be for name and age, for all the others will be returned an empty string. So we can have a report
* with more than two fields, but the name and the age will be returned each time only for the first two.
*
* If this example is too much complex refer to the method getFieldValue2, where is shown the first explained, and simple solution, where we
* expect two fields with a precise name.
*/
@Override
public Object getFieldValue(JRField jrField) throws JRException {
Integer fieldIndex;
if (fieldsNumber.containsKey(jrField.getName())) {
fieldIndex = fieldsNumber.get(jrField.getName());
}
else {
fieldsNumber.put(jrField.getName(), lastFieldsAdded);
fieldIndex = lastFieldsAdded;
lastFieldsAdded ++;
}
if (fieldIndex == 0) return lotNum[counter];
else if (fieldIndex == 1) return level[counter];
else if (fieldIndex == 2) return mean[counter];
else if (fieldIndex == 3) return SD[counter];
else if (fieldIndex == 4) return CV[counter];
else if (fieldIndex == 5) return N[counter];
else if (fieldIndex == 6) return mean2[counter];
else if (fieldIndex == 7) return SD2[counter];
else if (fieldIndex == 8) return CV2[counter];
else if (fieldIndex == 9) return N2[counter];
else if (fieldIndex == 10) return department[0];
else if (fieldIndex == 11) return instruementArray[0];
else if (fieldIndex == 12) return test[0];
else if (fieldIndex == 13) return method[0];
else if (fieldIndex == 14) return reagentArray[0];
else if (fieldIndex == 15) return month[0];
else if (fieldIndex == 16) return shift[0];
else if (fieldIndex == 17) return qcProduct[0];
else if (fieldIndex == 18) return days;
return "";
}
/**
* Return an instance of the class that implements the custom data adapter.
*/
public static JRDataSource getDataSource(){
return new GoImplementation();
}
}
Файл Jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3 -->
<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="GraphReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b0db03f9-1d9d-4eb5-8f2e-bc1174d4b926">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="CustomDataPackage\DataAdapter.xml"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="LeveyJen" uuid="7a90870e-2a65-494c-9a60-0c66448362de">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="CustomDataPackage\DataAdapter.xml"/>
<parameter name="Mean" class="java.lang.Double">
<property name="com.jaspersoft.studio.js.ic.ds" value="com.jaspersoft.studio.data.defaultdataadapter"/>
</parameter>
<parameter name="SD" class="java.lang.Double"/>
<parameter name="Days" class="java.lang.Integer"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="days" class="java.lang.Integer">
<fieldDescription><![CDATA[The dAYS Used]]></fieldDescription>
</field>
<field name="Mean" class="java.lang.Double">
<fieldDescription><![CDATA[The Mean]]></fieldDescription>
</field>
<field name="SD" class="java.lang.Double">
<fieldDescription><![CDATA[The Standard Deviation]]></fieldDescription>
</field>
<field name="Lot#" class="java.lang.Integer">
<fieldDescription><![CDATA[The lot number]]></fieldDescription>
</field>
<field name="CV" class="java.lang.Double">
<fieldDescription><![CDATA[The Coeficent Variation]]></fieldDescription>
</field>
<group name="Mean">
<groupExpression><![CDATA[$F{Mean}]]></groupExpression>
</group>
</subDataset>
<parameter name="Mean" class="java.lang.Double" evaluationTime="Early">
<defaultValueExpression><![CDATA[4.49]]></defaultValueExpression>
</parameter>
<parameter name="SD" class="java.lang.Double" evaluationTime="Early">
<defaultValueExpression><![CDATA[.30]]></defaultValueExpression>
</parameter>
<parameter name="days" class="java.lang.Integer" evaluationTime="Early">
<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="Lot#" class="java.lang.Integer">
<fieldDescription><![CDATA[The lot number]]></fieldDescription>
</field>
<field name="Level" class="java.lang.Integer">
<fieldDescription><![CDATA[The level]]></fieldDescription>
</field>
<field name="Mean" class="java.lang.Double">
<fieldDescription><![CDATA[The Mean]]></fieldDescription>
</field>
<field name="SD" class="java.lang.Double">
<fieldDescription><![CDATA[The Standard Deviation]]></fieldDescription>
</field>
<field name="CV" class="java.lang.Double">
<fieldDescription><![CDATA[The Coeficent Variation]]></fieldDescription>
</field>
<field name="N" class="java.lang.Integer">
<fieldDescription><![CDATA[The Sample]]></fieldDescription>
</field>
<field name="cMean" class="java.lang.Double">
<fieldDescription><![CDATA[The Cummulative Mean]]></fieldDescription>
</field>
<field name="cSD" class="java.lang.Double">
<fieldDescription><![CDATA[The Cummulative Standard Deviation]]></fieldDescription>
</field>
<field name="cCV" class="java.lang.Double">
<fieldDescription><![CDATA[The Cummulative Variation]]></fieldDescription>
</field>
<field name="cN" class="java.lang.Integer">
<fieldDescription><![CDATA[The Cummulative Sample]]></fieldDescription>
</field>
<field name="department" class="java.lang.String">
<fieldDescription><![CDATA[The Department]]></fieldDescription>
</field>
<field name="instrument" class="java.lang.String">
<fieldDescription><![CDATA[The Instrument]]></fieldDescription>
</field>
<field name="test" class="java.lang.String">
<fieldDescription><![CDATA[The Test]]></fieldDescription>
</field>
<field name="method" class="java.lang.String">
<fieldDescription><![CDATA[The Method]]></fieldDescription>
</field>
<field name="reagent" class="java.lang.String">
<fieldDescription><![CDATA[The Reagent]]></fieldDescription>
</field>
<field name="month" class="java.lang.String">
<fieldDescription><![CDATA[The Month]]></fieldDescription>
</field>
<field name="shift" class="java.lang.String">
<fieldDescription><![CDATA[The Shift]]></fieldDescription>
</field>
<field name="qcProduct" class="java.lang.String">
<fieldDescription><![CDATA[The Product Used]]></fieldDescription>
</field>
<field name="days" class="java.lang.Integer">
<fieldDescription><![CDATA[The dAYS Used]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="626">
<componentElement>
<reportElement x="20" y="0" width="200" height="200" uuid="80fb1a9e-e915-4f0a-8841-5ec4dc3e3e62">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="LeveyJen" uuid="b73b13da-6c82-476a-b05b-a76ceb8b0ace">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="40" uuid="870bbd63-dd2a-4a61-8488-ae55835df694">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:groupHeader groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupHeader>
<jr:groupFooter groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupFooter>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="dc2219e0-b6bb-4957-bf7e-ebad553c307d"/>
<text><![CDATA[days]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="c508b8f7-a940-4c21-8704-65df0d812521"/>
<textFieldExpression><![CDATA[$F{days}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="b7ae7382-8aa7-466f-96f8-ec5549e7ea7f">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:groupHeader groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupHeader>
<jr:groupFooter groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupFooter>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="4c916eef-3956-41c7-81b5-86ed59d8f816"/>
<text><![CDATA[Mean]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="3fba2b84-0d0a-4be9-8e39-2e883dc20962"/>
<textFieldExpression><![CDATA[$F{Mean}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="f50bd22f-deee-4ff7-b001-7e5515386adf">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:groupHeader groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupHeader>
<jr:groupFooter groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupFooter>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="960b3408-1558-4c43-9f90-366aef4bf4fa"/>
<text><![CDATA[SD]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="ce6ed33b-3b8a-4be7-96e9-4d6032342ba2"/>
<textFieldExpression><![CDATA[$F{SD}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="6ccc302d-bfbf-49c2-b1a9-1574cace4c20">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:groupHeader groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupHeader>
<jr:groupFooter groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupFooter>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="80e5d6b0-074c-4c5a-9a71-32d7e5ecbef9"/>
<text><![CDATA[Lot#]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="0d711de1-e894-4c2f-8247-f95a9ae14b14"/>
<textFieldExpression><![CDATA[$F{Lot#}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="361c4990-a417-4dbe-8fad-354daf2da30c">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:groupHeader groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupHeader>
<jr:groupFooter groupName="Mean">
<jr:cell style="Table_CH" height="30"/>
</jr:groupFooter>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="cb377e1c-7426-45d5-b063-c70ba13d3189"/>
<text><![CDATA[CV]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="a5b3191c-e675-4018-8727-6afec6544feb"/>
<textFieldExpression><![CDATA[$F{CV}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<lineChart>
<chart evaluationTime="Report">
<reportElement x="0" y="426" width="555" height="200" uuid="e6cccf0d-fe31-4417-ab27-f8a13aa142ad"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="LeveyJen" uuid="49b8c004-a74d-4b9f-a772-9f0996c2c7fc">
<datasetParameter name="Mean">
<datasetParameterExpression><![CDATA[$P{Mean}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="SD">
<datasetParameterExpression><![CDATA[$P{SD}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="Days">
<datasetParameterExpression><![CDATA[$P{days}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{Mean}]]></seriesExpression>
<categoryExpression><![CDATA[$F{days}]]></categoryExpression>
<valueExpression><![CDATA[$F{SD}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA[$F{days}]]></seriesExpression>
<categoryExpression><![CDATA[$F{days}]]></categoryExpression>
<valueExpression><![CDATA[$F{SD}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</lineChart>
</band>
</summary>
</jasperReport>