Create Chart's MapDataItem from Service Layer

Hi everyone,

I’m trying to create a Chart with ListDataProvider (my Chart doesn’t get data from any entity). Therefore I created a Service Bean for the chart, in which I run a query to fetch data from MYSQL DB.

But when I try to insert the data fetched from the query to a List , in order to pass it to the Chart Controller, I get this error of Cannot access DataItem, as you can see in the screenshots below.

Option 1: Using ResultSetHandler
image

Option 2: Let the query return a List of normal map objects and then map it to MapDataItem…
image

I’m thinking that DataItem objects cannot be accessed from Service Layer. That is somehow understandable. If it’s the case, then is there suitable class to use with the Chart’s ListDataProvider ?

Thank you in advance and kind regards,
Tuan Ngo

I’d return simple POJOs from the service (app-core) layer and then create date items for chart in Web layer (app-web).

1 Like

Thank you Yuriy !

That’s what I’m doing for this problem too. I was just wondering if there’s a better alternative. Having the service layer returning DataItem’s implementation would save me mapping the data at least once. :sweat_smile: