【发布时间】:2020-08-13 01:19:02
【问题描述】:
我正在使用charts_flutter 的自动标签饼图。我需要在点击/选择段时获取所选饼图段的数据值。但我不会在 selectionModel 的 changedListener 上获得回调。
var donutChart = new charts.PieChart(
series,
animate: true,
animationDuration: Duration(milliseconds: 500),
defaultInteractions: false,
selectionModels: [
new charts.SelectionModelConfig(
type: charts.SelectionModelType.action,
changedListener: _onSelectionChanged,
updatedListener: _onSelectionUpdated,
),
],
defaultRenderer: new charts.ArcRendererConfig(
arcWidth: 65,
arcRendererDecorators: [
new charts.ArcLabelDecorator(),
],
),
);
_onSelectionChanged(charts.SelectionModel model) {
print('In _onSelectionChanged');
final selectedDatum = model.selectedDatum;
print(selectedDatum.length);
if (selectedDatum.first.datum) {
print(model.selectedSeries[0].measureFn(model.selectedDatum[0].index));
chartAmountText = selectedDatum[0].datum.totalSpend.toString().split('.');
}
}
_onSelectionUpdated(charts.SelectionModel model) {
print('In _onSelectionUpdated');
if (selectedDatum.length > 0) {
print(selectedDatum[0].datum.category);
}
}
【问题讨论】: