Count user have same items in a table and create new table item name and count of user

i want to create a pie chart from new table.
In my order table i have user name and product name. different users have same items . I want to create new table Item name and user count.

i want to count item . it also increment after new order will happen.

example

Name Users
apple 25´
orange 10
pineapple 5

can you help me please

Hi,

You can create a valueCollectionDatasource for the pieChart data binding, for example:

<valueCollectionDatasource id="chartDs">
    <query>
        <![CDATA[select e.product, count(e.user.id) from demo$Order e group by e.product]]>
    </query>
    <properties>
        <property name="product" class="com.company.demo.entity.Product"/>
        <property name="count" datatype="int"/>
    </properties>
</valueCollectionDatasource>
<chart:pieChart id="pieChart"
                height="150px"
                datasource="chartDs"
                titleField="product"
                valueField="count"
                width="100%">
    <chart:legend position="RIGHT"/>
</chart:pieChart>

See the similar example in the workshop sample.

thank you for your help. now i have another problem. when I run this program chart is not displaying.

chartxmlnochart

There’s an error in your valueField: the “user” property does not exist in the chart’s datasource.
Set valueField="count", and is should work.

thank you so much… now it is working… oho oh :smiley:

1 Like