Hi,
In PieChart- titleField=“country” here country is coming from EnumCountry. So in title field it is displaying 1, 2 … etc…
But i need to display the corresponding values of 1, 2-> India, Russia. Can anyone say me, how to do this.
Thanks!!
Hi,
In PieChart- titleField=“country” here country is coming from EnumCountry. So in title field it is displaying 1, 2 … etc…
But i need to display the corresponding values of 1, 2-> India, Russia. Can anyone say me, how to do this.
Thanks!!
Unfortunately, enumeration values loaded with ValueCollectionDatasource now are loaded as primitives, in fact as “id” of enumeration. There is an issue https://youtrack.cuba-platform.com/issue/PL-9563, we are going to fix it in the near future.
At the moment, you can use the following workaround with ListDataProvider and DataManager.
XML:
<chart:pieChart id="pieChart"
titleField="title"
valueField="value"
height="100%"
width="100%"/>
Screen controller:
public class ExtAppMainWindow extends AppMainWindow {
@Inject
private PieChart pieChart;
@Inject
private DataManager dataManager;
@Override
public void init(Map<String, Object> params) {
super.init(params);
// load aggregated data with JPQL
List<KeyValueEntity> chartItems = dataManager.loadValues(
ValueLoadContext.create()
.setQuery(new ValueLoadContext.Query(
"select o.country, count(o.title) from demo$Order o group by o.country"))
.addProperty("country")
.addProperty("count"));
// convert enum ids to enum values
List<DataItem> dataItems = new ArrayList<>();
for (KeyValueEntity item : chartItems) {
dataItems.add(MapDataItem.of(
"title", Country.fromId(item.getValue("country")),
"value", item.getValue("count")));
}
// set data to chart
pieChart.setDataProvider(new ListDataProvider(dataItems));
}
}