mkeym Posted June 14, 2010 Posted June 14, 2010 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
rwigfall Posted June 14, 2010 Posted June 14, 2010 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
mkeym Posted June 15, 2010 Author Posted June 15, 2010 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.
rwigfall Posted June 15, 2010 Posted June 15, 2010 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") worksI 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now