imaNNeo / fl_chart

FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
https://flchart.dev
MIT License
6.77k stars 1.74k forks source link

What is best way for make slider change y axis with fl_chart #1604

Closed bird5523 closed 5 months ago

bird5523 commented 6 months ago

I need to make slider in chart by touch in line chart directly I have read some little code and so make this for test first. This is my code

` touchCallback: (FlTouchEvent event, LineTouchResponse? lineTouch) { if (event is FlPanUpdateEvent) { int? index = lineTouch ?.lineBarSpots?.last.spotIndex; //index user have touch

              final delta = event.details.localPosition.dy - _previousY;
              print(delta);
              if (delta < 0) {
                final touchedSpotIndex = index;
                if (touchedSpotIndex != null) {
                  updateSpots(
                      touchedSpotIndex,
                      lineTouch!.lineBarSpots!.last.y.toDouble() +
                          (2 * delta.abs()));
                }
              } else if (delta > 0) {
                final touchedSpotIndex = index;
                if (touchedSpotIndex != null) {
                  updateSpots(
                      touchedSpotIndex,
                      lineTouch!.lineBarSpots!.last.y.toDouble() -
                          (2 * delta.abs()));
                }
              }

              _previousY = event.details.localPosition.dy;
            }
          }

`

anyone can advice me or another idea.

Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision ba39319843 (4 days ago) • 2024-03-07 15:22:21 -0600 Engine • revision 2e4ba9c6fb Tools • Dart 3.3.1 • DevTools 2.31.1

Thanks you for your advice.

bird5523 commented 6 months ago

Now somebody. have this problem. you can use slidable_line_chart first. How ever if somebody have some idea pls tell. Thank you a lot.

imaNNeo commented 5 months ago

Duplicate issue,

check here and here for more information

https://user-images.githubusercontent.com/7009300/215731106-028d5cbc-7edd-44bd-829b-d3e2bea30334.mov