Jump to content

Recommended Posts

Posted

Hi,


I'm a newbie to Jasper Reports. I'm trying to build a Chart where i need Date field in X-Axis and Float or Integer Field in Y-Axis. I'm getting an error saying " java.lang.ClassCastException: java.sql.Date cannot be cast to java.lang.String".


Anyone please help me in solving this issue... I'm using JasperSoft Studio. I tried using "Bar Graph" and "Time Series Graph" as well. But getting the same error.


Below is my code,


<?xml version="1.0" encoding="UTF-8"?>

<!-- Created with Jaspersoft Studio version 6.0.4.final using JasperReports Library version 6.0.4  -->

<!-- 2015-05-12T13:47:40 -->

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreportshttp://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="AMT_Dataset" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1c863213-3621-49ce-baf9-7ead60d74ef5">

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Analytics"/>

<parameter name="No.of Days" class="java.lang.Integer">

<defaultValueExpression><![CDATA[0]]></defaultValueExpression>

</parameter>

<parameter name="MyDate" class="java.util.Date">

<parameterDescription><![CDATA[]]></parameterDescription>

<defaultValueExpression><![CDATA[new Date()]]></defaultValueExpression>

</parameter>

<queryString language="SQL">

<![CDATA[sELECT * FROM JACK WHERE Date >= $P{MyDate} - $P{No.of Days} AND Date <= $P{MyDate}]]>

</queryString>

<field name="Date" class="java.util.Date"/>

<field name="Type of Consumer" class="java.lang.String"/>

<field name="Electricity:Facility (kWh)" class="java.lang.Double"/>

<field name="Time" class="java.sql.Timestamp"/>

<field name="Electricity: UPS (kWh)" class="java.lang.Double"/>

<field name="Grinder:Electricity (kWh)" class="java.lang.Double"/>

<field name="Heating:Electricity (kWh)" class="java.lang.Double"/>

<field name="Cooling:Electricity (kWh)" class="java.lang.Double"/>

<field name="Electricity:HVAC (kWh)" class="java.lang.Double"/>

<field name="HVACFan:Fans:Electricity (kWh)" class="java.lang.Double"/>

<field name="Fans:Electricity (kWh)" class="java.lang.Double"/>

<field name="General:ExteriorLights:Electricity (kWh)" class="java.lang.Double"/>

<field name="General:InteriorLights:Electricity (kWh)" class="java.lang.Double"/>

<field name="Appl:InteriorEquipment:Electricity (kWh)" class="java.lang.Double"/>

<field name="Misc:InteriorEquipment:Electricity (kWh)" class="java.lang.Double"/>

<field name="Total KWH" class="java.lang.Float"/>

<field name="Water Heater:WaterSystems:Electricity (kWh)" class="java.lang.Double"/>

<field name="Rate" class="java.math.BigDecimal"/>

<field name="ID" class="java.lang.Integer"/>

<field name="Total Bill Amount" class="java.math.BigDecimal"/>

<background>

<band splitType="Stretch"/>

</background>

<title>

<band height="54" splitType="Stretch">

<property name="local_mesure_unitheight" value="pixel"/>

<property name="com.jaspersoft.studio.unit.height" value="px"/>

<staticText>

<reportElement x="210" y="10" width="170" height="30" uuid="3f74f3b6-63cb-4d08-880a-5dcf5c37b727"/>

<textElement textAlignment="Center">

<font fontName="Cambria" size="15" isBold="true"/>

</textElement>

<text><![CDATA[Electricity Consumption]]></text>

</staticText>

</band>

</title>

<columnHeader>

<band height="30">

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="0" y="0" width="81" height="30" forecolor="#050505" backcolor="#E64629" uuid="dd7a7b47-79b7-4cf9-8864-d482d35d0df6"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Date]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="81" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="53a8077b-83fc-4589-9bb1-f10a23ce8f68"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Type of Consumer]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="160" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="804552c6-ac1b-4273-9f9a-e01e9f1962de"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Time]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="239" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="878f7827-8ee5-4b83-b278-db70de8ddb68"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Total KWH]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="318" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="51ebd804-c9aa-4046-81d2-d59ddff8d565"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Rate]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="397" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="90a79e34-1352-4902-9418-ad48270c4ec6"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[iD]]></text>

</staticText>

<staticText>

<reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="476" y="0" width="79" height="30" forecolor="#050505" backcolor="#E64629" uuid="5ca6c846-2e9e-4bee-8e0f-28deb5833229"/>

<box>

<topPen lineWidth="1.0"/>

<leftPen lineWidth="1.0"/>

<bottomPen lineWidth="1.0"/>

<rightPen lineWidth="1.0"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font fontName="Bell MT" isBold="true"/>

</textElement>

<text><![CDATA[Total Bill Amount]]></text>

</staticText>

</band>

</columnHeader>

<detail>

<band height="30">

<textField>

<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="81" height="30" uuid="ec5dad6b-e21b-4994-9af8-d9f6c1a6dde4"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="81" y="0" width="79" height="30" uuid="69e07471-50a3-41ec-85c1-6950b30a670e"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Type of Consumer}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="160" y="0" width="79" height="30" uuid="e88114a4-0ba7-4f6d-94c2-ac99efd8ba5d"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Time}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="239" y="0" width="79" height="30" uuid="797c55b8-dcd3-4854-97e0-d339b35b89e5"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Total KWH}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="318" y="0" width="79" height="30" uuid="81bcf241-665e-4992-92ef-dff0680725b5"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Rate}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="397" y="0" width="79" height="30" uuid="4b85a078-ecf9-4095-8e15-d8eb9560701e"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>

</textField>

<textField>

<reportElement stretchType="RelativeToBandHeight" x="476" y="0" width="79" height="30" uuid="b7af2edb-0110-4dd4-95a0-b89d2b67c0e9"/>

<box>

<topPen lineWidth="1.0" lineColor="#000000"/>

<leftPen lineWidth="1.0" lineColor="#000000"/>

<bottomPen lineWidth="1.0" lineColor="#000000"/>

<rightPen lineWidth="1.0" lineColor="#000000"/>

</box>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{Total Bill Amount}]]></textFieldExpression>

</textField>

</band>

</detail>

<summary>

<band height="401">

<property name="local_mesure_unitheight" value="pixel"/>

<property name="com.jaspersoft.studio.unit.height" value="px"/>

<barChart>

<chart evaluationTime="Report">

<reportElement x="10" y="20" width="535" height="370" uuid="40441f2b-7a76-4d96-8943-57e43959bfc5"/>

<chartTitle/>

<chartSubtitle/>

<chartLegend/>

</chart>

<categoryDataset>

<categorySeries>

<seriesExpression><![CDATA[$F{Date}]]></seriesExpression>

<categoryExpression><![CDATA[" "]]></categoryExpression>

<valueExpression><![CDATA[$F{Total KWH}]]></valueExpression>

<labelExpression><![CDATA[$F{Date}]]></labelExpression>

</categorySeries>

</categoryDataset>

<barPlot>

<plot/>

<itemLabel/>

<categoryAxisFormat>

<axisFormat/>

</categoryAxisFormat>

<valueAxisFormat>

<axisFormat/>

</valueAxisFormat>

</barPlot>

</barChart>

</band>

</summary>

</jasperReport>

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...