Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the FlSpot touched in fl_charts

I have a LineChart where the default behaviour is that a tooltip with the y value shows up when you touch the chart.

How would i be able to get the x and y values of the point touched on the chart to save it in a variable for example.

It has to be in this property of the LineChart:

lineTouchData: LineTouchData(enabled: true),
like image 454
msmsms Avatar asked Oct 28 '25 05:10

msmsms


1 Answers

you need more parameters in your LineTouchData property. The touch callback will send you a list of touched spots

LineTouchData(
          enabled: true,
          touchCallback: (event, response) {
            if (event is FlTapUpEvent) {
              if (response != null && response.lineBarSpots != null) {
                // print(event);
                // print(response);
              }
            }
          },
        ),
like image 140
Zayin Krige Avatar answered Oct 29 '25 20:10

Zayin Krige



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!