Jump to content
Changes to the Jaspersoft community edition download ×

Date formatting in bar charts


dcooman

Recommended Posts

I am extracting data from MS SQL database with a timestamp and an integer.  The timestamp is a SQL date rounded to the hour (ie: 2010-02-02 14:00:00) and the integer is the number of phone calls during that hour.  I want to plot a bar chart with "hour of the day" on the x-axis and the number of calls on the y-axis.  I can get the chart to show correctly, but I cannot format the x-axis to just show the time (ex: 1 PM).  I have tried using the "Category Axis Tick Label Mask" which, according to what I have read, accepts format strings like those used in SimpleDateFormat.  I have tried variations of "h:mm a" (both with and without quotes) as well as standard format names like "SHORT".  In all cases the format is ignored and the entire date (2010-02-02 07:00:00.0) is printed.  I am using iReport version 3.5.0.  Do these format strings work on SQL TImestamp fields? Any help on what to use as a format string would be greatly appreciated. 

Link to comment
Share on other sites

  • 1 month later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

 I am having the same issue with version 3.7.1.  To my understanding it should follow the java.text.SimpleDateFormat standard and I should be able to use MM/dd in the field.  It is not an expression so I wouldn't expect to use quotes ("MM/dd") but I did try that as well.

I am not sure how this mask is supposed to work or if it is working.

 

edit:  note that I got around the issue by bringing in the date as a string formatted how I wanted instead of having jasper do it.  Not optimal but I got what I needed working :/  It seems like color and tick marks don't seem to be working for the category axis as well.  These all work for the vertical axis.



Post Edited by amthomas at 03/20/2010 04:33
Link to comment
Share on other sites

  • 1 year later...

I am using iReport 4.0.2 and I am having the same problem.  The "Category Axis Tick Label Mask" property doesn't appear to be working.  I tried "h:mm" with and without quotes.  My chart shows the average times to fill an order for time ranges between 10am and 1am the next day.  The category is a timestamp, but I only want to show the hour (1-12) and minute.  I tried formatting my time in my query (postgresql):

     to_char(x.time_of_day, 'HH12:MI') as order_start

but this will not work for my chart.  When I tried this, the chart didn't show all of my times.  For example, on 03/05/11, there weren't any orders at 10:00am, but there were orders at 10:00pm.  The chart only showed 10:00 once (in the am place), and the value was the value for 10pm, and 10pm was skipped on the chart.  The chart only showed times (the String) once.  The attached image shows the results I want, except I need the time in 12 hour format instead of 24 hour format.

How do I solve this "Category Axis Tick Label Mask" problem?

Any help would be greatly appreciated.  Thank you.



Post Edited by rcrosby at 07/20/2011 20:43
Link to comment
Share on other sites

  • 2 years later...

I am having issue converting String date to Date format to display in my chart in jasper ireport. I am getting date as "yyyy/mm/dd" string format from mongodb. But to display in the chart looks like ireport requires time to be date format. How do I convert. I am getting below error:

Error filling print... Error evaluating expression :      Source text : new SimpleDateFormat("MM/dd/yyyy").format($F{_id})

Setting up the file resolver...  net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : new SimpleDateFormat("MM/dd/yyyy").format($F{_id})      at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:244)      at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)      at net.sf.jasperreports.charts.fill.JRFillTimeSeries.evaluate(JRFillTimeSeries.java:146)      at net.sf.jasperreports.charts.fill.JRFillTimeSeriesDataset.customEvaluate(JRFillTimeSeriesDataset.java:104)      at net.sf.jasperreports.engine.fill.JRFillElementDataset.evaluate(JRFillElementDataset.java:155)      at net.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(JRCalculator.java:160)      at net.sf.jasperreports.engine.fill.JRFillDatasetRun.detail(JRFillDatasetRun.java:306)      at net.sf.jasperreports.engine.fill.JRFillDatasetRun.iterate(JRFillDatasetRun.java:261)      at net.sf.jasperreports.engine.fill.JRFillDatasetRun.evaluate(JRFillDatasetRun.java:208)      at net.sf.jasperreports.engine.fill.JRFillElementDataset.evaluateDatasetRun(JRFillElementDataset.java:231)      at net.sf.jasperreports.engine.fill.JRFillChart.evaluateDatasetRun(JRFillChart.java:1406)      at net.sf.jasperreports.engine.fill.JRFillChart.evaluateChart(JRFillChart.java:832)      at net.sf.jasperreports.engine.fill.JRFillChart.evaluateRenderer(JRFillChart.java:808)      at net.sf.jasperreports.engine.fill.JRFillChart.evaluate(JRFillChart.java:797)      at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)      at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1090)      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1055)      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:319)      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:158)      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: java.lang.IllegalArgumentException: Cannot format given Object as a Date      at java.text.DateFormat.format(Unknown Source)      at java.text.Format.format(Unknown Source)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)      at java.lang.reflect.Method.invoke(Unknown Source)      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)      at report645growth45chart_Dataset321_1394085272694_841544.evaluate(calculator_report645growth45chart_Dataset321_1394085272694_841544:162)      at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:231)      ... 28 more 

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

 

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