Flutter 如何使饼图具有交互性?没有得到图表';s饼图onChangedListener回调
我使用的是charts\u Flatter的自动标签饼图。我需要在点击/选择扇形图段时获取所选扇形图段的数据值。但我不会收到selectionModel的changedListener的回调Flutter 如何使饼图具有交互性?没有得到图表';s饼图onChangedListener回调,flutter,charts,pie-chart,Flutter,Charts,Pie Chart,我使用的是charts\u Flatter的自动标签饼图。我需要在点击/选择扇形图段时获取所选扇形图段的数据值。但我不会收到selectionModel的changedListener的回调 var donutChart = new charts.PieChart( series, animate: true, animationDuration: Duration(milliseconds: 500), defaultInteractions:
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);
}
}
首先,必须将
defaultInteractions
设置为true
,并将SelectionModelType
更改为info
:
@override
Widget build(BuildContext context) {
return new charts.PieChart(
seriesList,
animate: animate,
defaultInteractions: true,
selectionModels: [
new charts.SelectionModelConfig(
type: charts.SelectionModelType.info,
changedListener: _onSelectionChanged,
updatedListener: _onSelectionUpdated
),
],
);
}
然后在\u on selection changed
中,如果(selectedDatum.first.datum)不是一个bool,则删除此条件。并在已更新的选择中添加最终选定数据=模型选定数据如果
,则在之前添加code>