imaNNeo / imaNNeo/fl_chart

Dynamic tooltipBgColor in LineChart [Partial idea, i need help with the final part]

Open
#1,088 2 comments 0 reactions 0 assignees View on GitHub
good first issue Line Chart question
Dominant language
Dart
Stars
7.6k
Forks
2k
Avg merge
9d 1h
Merged PRs (30d)
2

Description

Hello,

I am trying to implement a dynamic `tooltipBgColor`, i achieved something, but i need help with the final part.

As you can see in the following code, i am able to get the "y" coordinates of the pressed spot, since it's printed correctly. The problem is that even if i change the color of `color_of_pressed_spot` to the one i want, the color is not displayed since i would need to call `setstate`, but i cannot do it in that moment or i will get an error. Any idea on how to do it?

```
LineChartData mainData() {
return LineChartData(
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: color_of_pressed_spot,
getTooltipItems: (List spots) {
return spots.map((spot) {
print("Spot y: ${spot.y}");
color_of_pressed_spot = changeColor(list_of_colors_i_want_to_use_for_each_spot_y, spot.y);

return LineTooltipItem(
getName(spot.y),
const TextStyle(color: Colors.white),
);
}).toList();
},
),
),);}
```

Contributor guide

Open the contributing guide

Research direction

Start with the LineChartData, LineTouchData, and LineTouchTooltipData configuration shown in the issue, then inspect how getTooltipItems receives each LineBarSpot. Determine how the tooltip background can follow spot.y without calling setState during the callback. Done means the tooltip background changes to the expected color for the pressed spot.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.