LineChart 中的 fl_chart 触摸响应问题

问题描述

我使用 fl_chart ^0.10.1 显示了一个折线图(在 Flutter ver 52.2.1 & 53.0.1 上测试)。 我正在从 csv 文件更新 FlSpots。

如果我触摸绘图中的某个位置,我将尝试获取索引或 Spot 对象。 但是,如果我触摸(轻按或长按)某处,我会从 touchResponse 获得一个空列表。

console

但我得到了情节本身的价值。我假设它在那里是因为内置的触摸处理程序。

plot

我正在尝试的代码:

              lineTouchData: LineTouchData(
                          touchCallback: (LineTouchResponse touchResponse) {
                        if (touchResponse.touchInput is FlPanEnd ||
                            touchResponse.touchInput is FlLongPressEnd) {
                          var spots = touchResponse.lineBarSpots;
                          setState(() {
                            var lengthList = spots.length;
                            print(
                                'touched spot---> ${spots.toString()},len--->$lengthList');
                          });
                        } else {
                          print('wait');
                        }
                      }),

我的最终目标是使用并传递触摸的索引来打开一个新屏幕/小部件。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)