Search code examples
chartsjasper-reportstime-series

JasperReports fails to render a Time Series Chart with error "null 'period' argument"


I have a relatively simple query that returns 3 fields of data per row, with a date. Something like this:

SELECT DATE(date) AS date, val1, val2
FROM tables
WHERE ...

From the report itself (detail band), I can confirm that all the "date" fields are non-NULL. The settings for my Time Series Chart are as follows:

  • TimePeriod: Day
  • Time Period Expression: $F{date}
  • (Series) Value $F{val2} - $F{val2}

The error I get is:

java.lang.IllegalArgumentException: Null 'period' argument.
at org.jfree.chart.util.ParamChecks.nullNotPermitted(ParamChecks.java:65)
at org.jfree.data.time.TimeSeriesDataItem.<init>(TimeSeriesDataItem.java:99)
at org.jfree.data.time.TimeSeries.addOrUpdate(TimeSeries.java:887)
...

I've even tried setting the "Time Period Expression" to the expression (null == $F{date} ? "foo" : $F{date}) just to see if I can get it to fail in a different say (like ClassCastException), but it still fails with the same message.

The data type for $F{date} is java.sql.Date, and the data type for the other two fields is java.lang.Long for both.

I'm using Jasper Studio 6.4.0 if that makes any difference.


Solution

  • I may have found an answer, and it looks like it might be a bug in JasperReports.

    I searched the web for answers for this question before posting, and most questions went unanswered or responses were along the lines of "happening to me, too" or "works for me" without any real answer.

    After making arrangements for every single possible null value to be handled, it still didn't work. So I tried changing the "TimePeriod" setting to "" just to see what would happen. No change, but going back to edit the chart, I noticed that "Day" was still the setting for the "TimePeriod" parameter. Weird.

    I really want day-level reports, but I was grasping at straws, so I changed the TimePeriod to "Week", and the report ran successfully.

    Then, I changed the "TimePeriod" from "Week" back to "Day" and it's running without error. So perhaps the default "TimePeriod" setting is in fact <NULL> but Jasper Studio shows that as "Day" when it's really not? I dunno. But try changing the TimePeriod to something else, then to what you really want.