views:

471

answers:

2

Hi, I want tom pass date as a field to the jrxml. Follwing is the code for it.

But it is not working. Its giving error as can not cast from date to number. Then how to convert it?

A: 

I cannot see the attached JRXML. However, open your JRXML file in a text editor, and check that the field is defined something like this:

<field name="MyDate" class="java.util.Date"/>
Sualeh Fatehi
Yes.it is defined like<field name="time" class="java.util.Date"/>
Aru
A: 

You are using the time field in the constructor of Date. No need for that.

Instead of this:

java.util.Date($F{time}.getTime())

use this:

$F{time}

If you want the long value of it: then use this

$F{time}.getTime()

UPDATE
I didn't notice you are using a chart, here is a new answer:

In charts, X and Y value expressions should be any Number object, check subclasses in Number Class JavaDoc, in your case you are getting the long value of your Time field, which cannot be cast to Number, you will need to define a new object, for example:

new Long($F{time}.getTime())


Side Note: in this case the report will compile and work, BUT, you are getting the number of milliseconds and using it in your chart. I don't think that is what you want exactly. So i would suggest extracting a specific field from your Date field like Day. Month, Year ... etc

medopal
I tried that.But its also not working.Its giving error as can not cast from long to number.
Aru
Hey thanks.Its working now.but as you said it is taking the values in millisecond.so how to display that milliseconds in hh mm ss format?
Aru
its not about the display, its about how you want your data to be presented. In your case, do you want to show how the CPU usage changed every 1 second? or every 1 minute? ...etc, the X expression should be set to this value. Also notice that the Label can have an expression also.
medopal
I want the hh:mm:ss format to display on x-axis.How to convert millisecond to this format in jrxml?Or is there any other way to display the time in hh:mm:ss format in jasper?
Aru