gpt4 book ai didi

flutter - 如何使饼图具有交互性?没有获取到 charts_flutter 的饼图 onChangedListener 回调

转载 作者:行者123 更新时间:2023-12-04 15:20:40 28 4
gpt4 key购买 nike

我正在使用 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);
}
}

最佳答案

首先,您必须将 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
),
],

);
}

然后在 _onSelectionChanged 中删除此条件 if (selectedDatum.first.datum) 因为它不是 bool。在 _onSelectionUpdated 中,在 if 之前添加 final selectedDatum = model.selectedDatum;

关于flutter - 如何使饼图具有交互性?没有获取到 charts_flutter 的饼图 onChangedListener 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63386748/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com