Jump to content
Changes to the Jaspersoft community edition download ×

Format String to Number iReport


mkeym

Recommended Posts

Hey,

i want to generate a xyline chart in ireport with existing database.

I use for x-axis a field in string but i need to convert to number.

When i use

<field name="DESCRIPTION" class="java.lang.String" />
<field name="HALFHOUR" class="java.lang.String" />
<field name="VALUEA" class="java.lang.Double" />
........
    <xyLineChart>
                <chart>
                    <reportElement x="126" y="32" width="311" height="253"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <xyDataset>
                    <xySeries>
                        <seriesExpression><![CDATA[$F{DESCRIPTION}]]></seriesExpression>
                        <xValueExpression><![CDATA[new java.text.SimpleDateFormat("hh24:mi").format(new java.text.SimpleDateFormat("hh24:mi").parse($F{HALFHOUR}))]]></xValueExpression>
                        <yValueExpression><![CDATA[$F{VALUEA}]]></yValueExpression>
                    </xySeries>
                </xyDataset>
                <linePlot>
                    <plot/>
                    <categoryAxisFormat>
                        <axisFormat>
                            <labelFont/>
                            <tickLabelFont/>
                        </axisFormat>
                    </categoryAxisFormat>
                    <valueAxisFormat>
                        <axisFormat>
                            <labelFont/>
                            <tickLabelFont/>
                        </axisFormat>
                    </valueAxisFormat>
                </linePlot>
            </xyLineChart>

When i try to compile i get the message: Cannot cast from string to number.

 

Can somebody help ply and can i use this template in Eclipse/JasperReports?

 

Thanks and Regards

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

mkeym:

Not sure about using your XML template in Eclipse/JasperReports but if it's attempting to compile...maybe it works.

As far as the cast error: Try to type cast your Strings to Integers by using intValue. (see the modified code sample)

Hope this helps.

 

Regards

 

 

Code:


Post Edited by rwigfall at 06/14/2010 20:52
Link to comment
Share on other sites

Now, when i try to use the method intValue() i get a new error: The method intValue() is undefined for the type String

 

I actually also try to create LineChart but it can't show time parameter in x-axis. The x-axis is without a descirption of Halfhour String. Here the chart seems to be ok but i want to create it with XYLineChart or maybe i use TimeSeries?

If i use this template in eclipse i get over 60 errors. But first of all i need to create it in ireport.


Link to comment
Share on other sites

Oops...can't use intValue to convert a date type. Also you don't need to convert ValueA to integer so omit that as well.

I think you want to convert the field $F{HALFHOUR} from string to integer then use $F{HALFHOUR}.intValue()

 

Are you sure your java is correct? I didn't see "i" as an acceptable pattern letter in the javadoc - string java.text.SimpleDateFormat("hh24:mi"), remove the "i" so you have java.text.SimpleDateFormat("hh24:m") or java.text.SimpleDateFormat("H:m") works

I suggest making sure the java code is correct first, this way you isolate your errors and troubleshooting. (I tried java.text.SimpleDateFormat("hh24:mi") and got errors)

 

If I am helpful please give Karma points.

Link to comment
Share on other sites

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...