在Card中使用条形图时,显示不正确。数据加载且set进去了,但是bar的高度为0。

<card themeNames="elevated" classNames="home-bottom-card home-bottom-card-middle" title="隐患">
<content>
<charts:chart id="troubleChart" width="100%" height="100%">
<charts:tooltip trigger="AXIS">
<charts:axisPointer type="SHADOW"/>
</charts:tooltip>
<charts:xAxes>
<charts:xAxis/>
</charts:xAxes>
<charts:yAxes>
<charts:yAxis/>
</charts:yAxes>
<charts:series>
<charts:bar name="全部" animation="true"/>
<charts:bar name="未关闭" animation="true"/>
</charts:series>
</charts:chart>
</content>
</card>
使用ListChartItems动态提供数据:
private DataSet loadTroubleChart() {
// 查询隐患类别一级节点
List<Catalog> catalogs = catalogUtils.getRootCatalogs(organizationId, CatalogType.TROUBLE);
// 查询每个一级节点下隐患的数量
ListChartItems<MapDataItem> items = new ListChartItems<>();
for (Catalog catalog : catalogs) {
int total = dataManager.loadValue("select count(distinct e) from TroubleOrder e where e.organizationId = :organizationId and e.catalogId in :catalogIds", Integer.class)
.parameter("organizationId", organizationId)
.parameter("catalogIds", treeEntityUtils.allChildren(Catalog.class, catalog, true).stream().map(Catalog::getId).toList())
.optional()
.orElse(0);
if (total > 0) {
int opened = dataManager.loadValue("select count(distinct e) from TroubleOrder e where e.organizationId = :organizationId and e.status <> :status and e.catalogId in :catalogIds", Integer.class)
.parameter("organizationId", organizationId)
.parameter("catalogIds", treeEntityUtils.allChildren(Catalog.class, catalog, true).stream().map(Catalog::getId).toList())
.parameter("status", TroubleOrderStatus.CLOSE)
.optional()
.orElse(0);
items.addItem(new MapDataItem((Map.of("category", catalog.getName(), "total", total, "opened", opened))));
}
}
// 返回图表数据集
return new DataSet()
.withSource(
new DataSet.Source<MapDataItem>()
.withDataProvider(items)
.withCategoryField("category")
.withValueFields("total")
);
}
// 隐患图表数据
uiAsyncTasks.supplierConfigurer(this::loadTroubleChart)
.withResultHandler(dataSet -> troubleChart.setDataSet(dataSet))
.supplyAsync();