Jump to content
We've recently updated our Privacy Statement, available here ×

Sorting data on the category axis of a chart


godbole

Recommended Posts

Hello,

I'm new to JasperReports and currently generating a report grouped on application listing the date, total messages and total bytes for each application. The groups are listed alphabetically. I'm also creating a line chart on the same data that has date on the category (X) axis, messages on the value (Y) axis and applications as the series. The report generates fine but on the chart the date on the category axis is not in the logical order. This seems to be because the first application in the report has no data for the first 10 days of the month so the chart starts plotting from Sep 10 and goes till the 30th, then plots Sep. 1 through Sep. 9 (that too is not all in order). How do I sort or order the date on the X axis? Given below is an example of the report:

Application: ABC

Date  Total Msgs  Total Bytes

=============================

Sept 10

.

.

Sept 30

=============================

Application:XYZ

Date  Total Msgs  Total Bytes

=============================

Sept 1

.

.

.

Sept 30

=============================

An image of the chart is attached for your reference.

Any help is greatly appreciated!

Thanks!

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

godbole,

 

bulut's idea is good. A Timeseries chart may be more appropriate, and it may give better results.

 

It sounds like your query is the problem. It seems to return text where you logically want a date. You'll need to modify the report to return a date rather than a string, or continue to return the string but force the SQL results to be ordered correctly by the database.

 

Regards,
Matt

Link to comment
Share on other sites

Bulut,

Thanks for the suggestion. I tried time series but am not able to get it to display correctly. I've tried many things among the first was the exact options which work for the line chart. Please find attached images for the chart settings and the chart that shows up. Please help! I cannot find any documentation on how to set time series values correctly.

 

Matt,

The date field type is set as java.util.date (by default it gets set to timestamp but I'm changing it to date). In the database it is as type date and not string. I've set the order by to date first and then application and the increment group is set to the date group but yet the chart takes the first value it finds in the first application group.

Another thing I tried that seems to work is subreports. I defined a subreport with just the chart in it and order by date only and embedded that in the main report that was ordered by application and that seems to work but this seems to be a complicated way of acheiving something that should be quite simple!

Link to comment
Share on other sites

hmmm... wonder if this is a bug with the image upload function of the forum.. this time I'm sure I uploaded 2 different images.. the image name is also changed and maybe overwriting the earlier uploaded images, maybe ther's a limit on the image name (although the names were not that big, the biggest was TimeSeriesSettings1.jpg)

oh well.. here is the third one of the chart... sorry for the multiple posts on this!

Link to comment
Share on other sites

godbole,

 

Having the date fields mis-ordered is commonly a String vs Date issue, but in your case it seems the problem is completely different. Now my first thought is this: Use a second query in the report. It should give you the same benefit as you got from creating a subreport, but it will be much easier to create and to maintain. In iReport 3.1.2 you right-click the highest level node in the Report Inspector and chose "Add Dataset". The query in your dataset will probably be identical to the main query except for the ordering.

 

The timeseries chart details that you posted show a Time period of "Month". From what you described earlier, this should be "Day" instead. See if changing that helps. If not, then please start a new thread with the exact errors that you're hitting. Or maybe don't bother if the above suggestion gets things working well enough.  ;-)

 

Regards,
Matt

Link to comment
Share on other sites

I tried adding a dataset before also just like you mention but could not get the chart to work. I tried it again just now and it works like a charm! Thanks!

 

The timeseries chart gives me an error when the period is set to Day. Funnily enough this works for a colleague of mine on his database. I've included the error below. I'll also put this in a new thread as you suggested.

 

ErrorÂfillingÂprint...ÂNullÂ'period'Âargument.

java.lang.reflect.InvocationTargetException ÂÂÂÂatÂjava.awt.EventQueue.invokeAndWait(UnknownÂSource) ÂÂÂÂatÂjavax.swing.SwingUtilities.invokeAndWait(UnknownÂSource) ÂÂÂÂatÂcom.jaspersoft.ireport.designer.compiler.prompt.Prompter.promptForParameters(Prompter.java:259) ÂÂÂÂatÂcom.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:731) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986) CausedÂby:Âjava.lang.NullPointerException ÂÂÂÂatÂcom.jaspersoft.ireport.designer.compiler.prompt.Prompter$1.run(Prompter.java:65) ÂÂÂÂatÂjava.awt.event.InvocationEvent.dispatch(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventQueue.dispatchEvent(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventDispatchThread.pumpOneEventForHierarchy(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventDispatchThread.pumpEventsForHierarchy(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventDispatchThread.pumpEvents(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventDispatchThread.pumpEvents(UnknownÂSource) ÂÂÂÂatÂjava.awt.EventDispatchThread.run(UnknownÂSource) java.lang.IllegalArgumentException:ÂNullÂ'period'Âargument. ÂÂÂÂatÂorg.jfree.data.time.TimeSeries.addOrUpdate(TimeSeries.java:693) ÂÂÂÂatÂnet.sf.jasperreports.charts.fill.JRFillTimeSeriesDataset.customIncrement(JRFillTimeSeriesDataset.java:150) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillElementDataset.increment(JRFillElementDataset.java:179) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(JRCalculator.java:152) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:682) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:888) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:791) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234) ÂÂÂÂatÂcom.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:890) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986)Â

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

 

Thanks again for all your help!

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