2014-08-29 282 views

回答

1

添加一個變量(例如v_sum)以獲得列的總和(例如EMPLOYEEID)。

<variable name="v_sum" class="java.lang.Integer" calculation="Sum"> 
    <variableExpression><![CDATA[$F{EMPLOYEEID}]]></variableExpression> 
</variable> 

並選擇你想要得到的百分比值,然後選擇屬性提起列2: -

Evaluation Time-  Auto 

例報告中,你可以與示例數據庫(HSQLDB)運行以下命令: -

<?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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="76072389-4335-4fd9-b45a-111b679776c9"> 
<property name="ireport.zoom" value="1.0"/> 
<property name="ireport.x" value="0"/> 
<property name="ireport.y" value="0"/> 
<queryString> 
    <![CDATA[select EMPLOYEEID from orders]]> 
</queryString> 
<field name="EMPLOYEEID" class="java.lang.Integer"/> 
<variable name="v_sum" class="java.lang.Integer" calculation="Sum"> 
    <variableExpression><![CDATA[$F{EMPLOYEEID}]]></variableExpression> 
</variable> 
<columnHeader> 
    <band height="28" splitType="Stretch"> 
     <staticText> 
      <reportElement uuid="00bd99b4-690f-4eea-aebe-08b0cdcfcec2" x="15" y="6" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[EmployeeID]]></text> 
     </staticText> 
     <staticText> 
      <reportElement uuid="6396c710-73d9-407f-ba02-4aceb524cb75" x="172" y="6" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[%]]></text> 
     </staticText> 
    </band> 
</columnHeader> 
<detail> 
    <band height="20" splitType="Stretch"> 
     <textField> 
      <reportElement uuid="dbbdb209-dbd4-4dbb-a454-32968c31ec79" x="14" y="0" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{EMPLOYEEID}]]></textFieldExpression> 
     </textField> 
     <textField evaluationTime="Auto"> 
      <reportElement uuid="f14e9e42-5486-4204-974c-c2c148ab73c7" x="172" y="0" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[(100*$F{EMPLOYEEID})/$V{v_sum}]]></textFieldExpression> 
     </textField> 
    </band> 
</detail> 

+0

請你告訴我這是什麼評價時屬性要這麼做? – 2014-09-01 06:35:33

+0

它適合你嗎? – Sharad 2014-09-01 07:26:03

+0

有沒有什麼辦法可以在變量中做這個計算?因爲我想根據它的值對這個(百分比)列進行排序。 – 2014-09-01 12:28:06