Jump to content
Changes to the Jaspersoft community edition download ×

How to convert string to date to display in the chart


mizan_1

Recommended Posts

How to convert string to date to display in the chart. Dataset is returning string format date and string format number fields coming out of mongodb. I need to plot chart with date and number but both are in string format. How dow I convert those string format date to java util date and string format number to regular number so that chart can be desplayed properly. Currently I am getting error as both date and numbers are string format.

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Error filling print... Error evaluating expression : 
    Source text : $F{_id}

Setting up the file resolver... 
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : $F{_id} 
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:308) 
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:582) 
    at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:181) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1259) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1233) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1577) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:932) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845) 
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87) 
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446) 
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276) 
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745) 
    at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891) 
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) 
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) 
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '2014/01/01' with class 'java.lang.String' to class 'java.util.Date' 
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360) 
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599) 
    at report645growth45chart_1394143189167_342593.evaluateEstimated(calculator_report645growth45chart_1394143189167_342593:268) 
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:295) 
    ... 15 more 

Print not filled. Try to use an EmptyDataSource... 

Link to comment
Share on other sites

Hello,

You will need to do something like this example:

SimpleDateFormat("dd/MM/yy").parse("01/01/01")

Where the fields evaluation time needs to be set to "Report"

& Calculation Type to "First" 

& reset type = "None".
 

Below is an example of use:

(New SimpleDateFormat("dd/mm/yy").format($F{birthDate})

Enjoy!

Link to comment
Share on other sites

Thanks. But I am bit confused. where should I put that SimpleDateFormat("dd/MM/yy").parse("01/01/01") expression, and fields calculation type and reset type value? when I go to chart data -> details, it opens up window to select field and few transformation condition (like, toString, valuOf etc). But I don't see any place to set calculation type, reset type and also where should I place "SimpleDateFormat("dd/MM/yy").parse("01/01/01")"?
Link to comment
Share on other sites

Hi,

If your date field is $F{DateField}, if it is a string, if you need to provide a java.util.date datatype, then instead of using the $F{DateField} expression, use the following expression :

new SimpleDateFormat("yyyy/mm/dd").parse($F{DateField})

Possible optimization : If you use this information in several expressions, it might be better to evaluate it once for every row and to use this evaluation : create a variable with the previous expression and to use this variable instead of the field everywhere. The String to date conversion will occur only once and its result will be used everywhere.

Regards

François

Link to comment
Share on other sites

ok, thanks. One issue is, this created variables not showing up in the chart details->expression editor. So I am unable to add that variable as x-axis. How do I make that variable visible/ available in the expression editor to add that as x-axis in my chart?
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...