Search code examples
chartsjasper-reportsireport

JasperReports. How to count records in time interval and display it in chart


I have a table for storing event information. When event is launched it creates new record in table. Each record contains timestamp value that represents time when event was launched.

For example:

Table EVENT_DATA
integer ID
varchar NAME
timestamp STARTIME
etc...

What I need to do is to calculate amount of events in each hour of a day and display them in a chart. Is it possible to achieve this only by means of iReport or JapsersoftStudio?


Solution

  • Yes, you just need to work the query which will return your data.

    I haven't tested it but it should be something like this:

    SELECT EXTRACT(HOUR FROM startime), count(id)
    FROM EVENT_DATA
    WHERE startime BETWEEN :a AND :b
    GROUP BY EXTRACT(HOUR FROM startime)
    

    Of course the query depends on your database.