Vaadin Charts / JPAContainer and SQL "Groups"

Just listened to the Webinar - thank you for going to the trouble. I asked a question via Twitter regarding connecting a Chart to a database via “group by”. I am sure that I have a weakness in my understanding of the JPAContainer and / or SQL, however I am trying to develop a solution for the following:

If I have a simple table that contains data relating to web site hits. It may have the following structure:


 ID | LONG 
 DateOfHit | DATE 
 Page | VARCHAR

Say I want to bar graph the number of hits per month and in the same graph the hits per Page/month. How to I put this together with the JPAContainer and the Charts Plugin.

Hi,

I guess this question is bit more of JPA than Charts, but I built a one example project using similar entity that you have:

https://github.com/mstahv/jpagroupbychart

AFAIK jpql don’t have native methods to group dates by month or week, so you probably need to use some implementation specific extension. I used eclipselink and its FUNC method. Different series are created for different pages and series are then visualised using stacked area chart.

I also left out JPAContainer altogether as I see no pros for it in this case. It is probably possible by using some advanced criteria query API and ContainerDataSeries wrapper, but what is possible is not always wise.

In the example there is a JPAContainer backed table that can be used to modify data though.

I hope I answered the right question :slight_smile:

cheers,
matti

Thanks for the quick reply. That was really helpful!