Chart event listener is unable to get entity with Value Datasource

Hi there,
I created both serial and pie charts with Value Datasource successfully. Then when I try to add Chart.GraphItemClickEvent or SlicePullOutEvent listener respectively, the event.getItem() ALWAYS returns null.

Here is a test code of SlicePullOutEvent listener based on your demo project:


public class ValueDsDemo extends AbstractWindow {
    @Inject
    private CollectionDatasource<KeyValueEntity, Object> salesDs;
    @Inject
    private Chart orderByCustomerChartId;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);

        orderByCustomerChartId.addSlicePullOutListener(event ->{
                Entity entity = event.getItem();
                if(entity != null){
                    showNotification("entity is NOT null: " +  entity.getId().toString(), NotificationType.HUMANIZED);
                }
                else
                {
                    showNotification("entity is null! ", NotificationType.HUMANIZED);
                }
        });
}

“entity is null!” is printed out.
My project also needs to be able to add ChartItemClickListener for SerialChart (type: COLUMN).

Ideally if you could update the demo project (demo-64-value-ds) by adding event handler, and make the entity be available in the handler, that would be great.

Thanks for your help,
-Mike

Hi,

At the moment, it is a Known issue PL-7655. We will fix it in one of the next bug fix versions.

Currently, Chart fires events with entity only if it is connected with normal Datasource. As workaround you can use non-persistent entity and CollectionDatasource with Do not refresh option.

Hi Yuriy,

Could you point me to an example/demo project that uses non-persistent entity for displaying Charts?

Thank you very much,
-Mike

Hi,

You can read about meta class usage with charts in our charts manual: https://doc.cuba-platform.com/charts-6.4/cdb_create_model.html

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-7655