Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically changing tooltipBgColor #1348

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
125499a
Created a function to change the background color of the tooltip for …
May 25, 2023
3918a35
updated bar_chart.md file about dynamic tooltip background change
Jun 13, 2023
3cbd748
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
5ee106a
solved merge conflicts
Aug 29, 2023
c2a9c92
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
98dd2ab
made changes related to dynamic tooltip backgroud color changes for s…
Jun 19, 2023
2665739
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
14240d0
docs: Updated breaking change information
Jun 22, 2023
2aad839
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
be5b886
fix: Fix test cases failures,change description of getTooltipColor me…
Jul 12, 2023
de8355c
resolved conflicts in changelog.md
Aug 29, 2023
1851dd6
removed unnecessary comments and merge remote changes
Jul 12, 2023
35606b9
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
a82d13f
docs: Updated breaking change information
Jun 22, 2023
6574f0d
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
1b2b6d8
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
b444cad
solved merge conflicts
Jul 12, 2023
ca5dccb
fix: Removed typing mistakes and replace switch statements to dart 3 …
Aug 5, 2023
44efdb6
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
0a259a8
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
e4f6bc2
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
ea62211
docs: Updated breaking change information
Jun 22, 2023
561109b
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
6eaa299
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
20fdbfd
docs: Updated breaking change information
Jun 22, 2023
7a57edc
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
748a39d
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
e22859e
solved merge conflicts
Jul 12, 2023
149d007
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
2a4c11f
Created a function to change the background color of the tooltip for …
May 25, 2023
ecbfe0a
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
5a40acd
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
5f04986
docs: Updated breaking change information
Jun 22, 2023
583d742
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
01e4bff
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
07d3e92
docs: Updated breaking change information
Jun 22, 2023
c9ccb8e
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
ead6977
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
a3db848
solved merge conflicts
Jul 12, 2023
d6828a2
Merge branch 'master' into feature/dynamic-tooltip-bgcolor
imaNNeo Nov 5, 2023
c459b18
Created a function to change the background color of the tooltip for …
May 25, 2023
2ef9257
updated bar_chart.md file about dynamic tooltip background change
Jun 13, 2023
db4ec33
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
4b35ff4
solved merge conflicts
Aug 29, 2023
d1740af
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
f651139
made changes related to dynamic tooltip backgroud color changes for s…
Jun 19, 2023
e7de07f
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
ec6d5bb
docs: Updated breaking change information
Jun 22, 2023
39efab6
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
5da1c26
fix: Fix test cases failures,change description of getTooltipColor me…
Jul 12, 2023
362853e
removed unnecessary comments and merge remote changes
Jul 12, 2023
bde51a0
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
bb300a0
docs: Updated breaking change information
Jun 22, 2023
e6e2afe
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
d98bde2
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
2e7d878
solved merge conflicts
Jul 12, 2023
d1fe5bc
fix: Removed typing mistakes and replace switch statements to dart 3 …
Aug 5, 2023
71b9f9b
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
bb19943
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
69af54a
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
739288d
docs: Updated breaking change information
Jun 22, 2023
c7fc739
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
6114d98
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
34c0388
docs: Updated breaking change information
Jun 22, 2023
b0e0e99
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
784e9b5
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
4b55016
solved merge conflicts
Jul 12, 2023
3875e64
continue with line chart dynamic tooltip bg color changes
Jun 15, 2023
5ee4ddd
Created a function to change the background color of the tooltip for …
May 25, 2023
03f3fbc
feat: Added dynamic tooltip for background color for line chart
Jun 16, 2023
3435fa5
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
48443fd
docs: Updated breaking change information
Jun 22, 2023
f102b37
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
67a7399
feat: Remove old property called tooltipBgColor for Bar,Line and Scat…
Jun 22, 2023
4dbef3d
docs: Updated breaking change information
Jun 22, 2023
f73fe44
fix: removed comments from bar chart data and scatter chart painter c…
Jul 11, 2023
67c9d2f
fix: removed unnecessary comments and changed description of getting …
Jul 12, 2023
b62b4e3
solved merge conflicts
Jul 12, 2023
b6ef4ad
Fix CHANGELOG.md conflicts
imaNNeo Nov 5, 2023
274d888
Merge branch 'feature/dynamic-tooltip-bgcolor' of https://github.com/…
imaNNeo Nov 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
## nextVersion
* **FEATURE** (by @Dartek12): Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine), #1197
* **FEATURE** (by @apekshamehta) Added new method called getTooltipColor for axis charts (bar,line,scatter) to change backgroud color of tooltip dynamically.[issue](https://github.com/imaNNeo/fl_chart/issues/1279).
* **BREAKING** (by @apekshamehta) Removed tooltipBgColor property from Bar, Line and Scatter Charts.


## 0.64.0
apekshamehta marked this conversation as resolved.
Show resolved Hide resolved
* **BUGFIX** (by @Anas35) Fix Tooltip not displaying when value from BackgroundBarChartRodData is less than zero. #1345.
* **BUGFIX** (by @imaNNeo) Fix Negative BarChartRodStackItem are not drawn correctly bug, #1347
* **BUGFIX** (by @imaNNeo) Fix bar_chart_helper minY calculation bug, #1388
* **IMPROVEMENT** (by @imaNNeo) Consider fraction digits when formatting chart side titles, #1267

apekshamehta marked this conversation as resolved.
Show resolved Hide resolved

## 0.63.0
* **BUGFIX** (by @imaNNeo) Fix PieChart crash on web-renderer html by ignoring `sectionsSpace` when `Path.combine()` does not work (it's flutter engine [issue](https://github.com/flutter/flutter/issues/44572)), #955
* **BUGFIX** (by @imaNNeo) Fix ScatterChart long-press interaction bug (disappears when long-pressing on the chart), #1318
Expand Down
18 changes: 15 additions & 3 deletions example/lib/presentation/samples/bar/bar_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,19 @@ class BarChartSample1State extends State<BarChartSample1> {
return BarChartData(
barTouchData: BarTouchData(
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.blueGrey,
getTooltipColor: (group) {
Color bgColor = switch (group.x) {
0 => AppColors.contentColorPurple.withAlpha(100),
1 => AppColors.contentColorYellow.withAlpha(100),
2 => AppColors.contentColorBlue.withAlpha(100),
3 => AppColors.contentColorOrange.withAlpha(100),
4 => AppColors.contentColorPink.withAlpha(100),
5 => AppColors.contentColorRed.withAlpha(100),
6 => AppColors.contentColorPurple.withAlpha(150),
_ => throw Error(),
};
return bgColor;
},
tooltipHorizontalAlignment: FLHorizontalAlignment.right,
tooltipMargin: -10,
getTooltipItem: (group, groupIndex, rod, rodIndex) {
Expand Down Expand Up @@ -202,8 +214,8 @@ class BarChartSample1State extends State<BarChartSample1> {
children: <TextSpan>[
TextSpan(
text: (rod.toY - 1).toString(),
style: TextStyle(
color: widget.touchedBarColor,
style: const TextStyle(
color: Colors.white, //widget.touchedBarColor,
fontSize: 16,
fontWeight: FontWeight.w500,
),
Expand Down
4 changes: 3 additions & 1 deletion example/lib/presentation/samples/bar/bar_chart_sample2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class BarChartSample2State extends State<BarChartSample2> {
maxY: 20,
barTouchData: BarTouchData(
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.grey,
getTooltipColor: ((group) {
return Colors.grey;
}),
getTooltipItem: (a, b, c, d) => null,
),
touchCallback: (FlTouchEvent event, response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _BarChart extends StatelessWidget {
BarTouchData get barTouchData => BarTouchData(
enabled: false,
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.transparent,
getTooltipColor: (group) => Colors.transparent,
tooltipPadding: EdgeInsets.zero,
tooltipMargin: 8,
getTooltipItem: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class _BarChartSample7State extends State<BarChartSample7> {
enabled: true,
handleBuiltInTouches: false,
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.transparent,
getTooltipColor: (group) => Colors.transparent,
tooltipMargin: 0,
getTooltipItem: (
BarChartGroupData group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _LineChart extends StatelessWidget {
LineTouchData get lineTouchData1 => LineTouchData(
handleBuiltInTouches: true,
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: Colors.blueGrey.withOpacity(0.8),
getTooltipColor: (touchedSpot) => Colors.blueGrey.withOpacity(0.8),
),
);

Expand Down
17 changes: 16 additions & 1 deletion example/lib/presentation/samples/line/line_chart_sample3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,22 @@ class _LineChartSample3State extends State<LineChartSample3> {
}).toList();
},
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: widget.tooltipBgColor,
getTooltipColor: (touchedSpot) {
Color bgColor = switch ((
touchedSpot.x.toInt(),
touchedSpot.y.toDouble()
)) {
(0, 1.3) => AppColors.contentColorPurple.withAlpha(100),
(1, 1) => AppColors.contentColorYellow.withAlpha(100),
(2, 1.8) => AppColors.contentColorBlue.withAlpha(100),
(3, 1.5) => AppColors.contentColorOrange.withAlpha(100),
(4, 2.2) => AppColors.contentColorPink.withAlpha(100),
(5, 1.8) => AppColors.contentColorRed.withAlpha(100),
(6, 3) => AppColors.contentColorPurple.withAlpha(150),
_ => throw Error(),
};
return bgColor;
},
getTooltipItems: (List<LineBarSpot> touchedBarSpots) {
return touchedBarSpots.map((barSpot) {
final flSpot = barSpot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class _LineChartSample5State extends State<LineChartSample5> {
}).toList();
},
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: Colors.pink,
getTooltipColor: (touchedSpot) => Colors.pink,
tooltipRoundedRadius: 8,
getTooltipItems: (List<LineBarSpot> lineBarsSpot) {
return lineBarsSpot.map((lineBarSpot) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/presentation/samples/line/line_chart_sample8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ class _LineChartSample8State extends State<LineChartSample8> {
);
}).toList();
},
touchTooltipData: const LineTouchTooltipData(
tooltipBgColor: AppColors.contentColorBlue,
touchTooltipData: LineTouchTooltipData(
getTooltipColor: (touchedSpot) => AppColors.contentColorBlue,
),
),
borderData: FlBorderData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LineChartSample9 extends StatelessWidget {
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
maxContentWidth: 100,
tooltipBgColor: Colors.black,
getTooltipColor: (touchedSpot) => Colors.black,
getTooltipItems: (touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
final textStyle = TextStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,23 @@ class _ScatterChartSample2State extends State {
: SystemMouseCursors.click;
},
touchTooltipData: ScatterTouchTooltipData(
tooltipBgColor: Colors.black,
getTooltipColor: (ScatterSpot touchedBarSpot) {
Color bgColor = switch ((
touchedBarSpot.x.toInt(),
touchedBarSpot.y.toInt()
)) {
(4, 4) => AppColors.contentColorPurple.withAlpha(100),
(2, 5) => AppColors.contentColorYellow.withAlpha(100),
(4, 5) => AppColors.contentColorBlue.withAlpha(100),
(8, 6) => AppColors.contentColorOrange.withAlpha(100),
(5, 7) => AppColors.contentColorPink.withAlpha(100),
(7, 2) => AppColors.contentColorRed.withAlpha(100),
(3, 2) => AppColors.contentColorPurple.withAlpha(150),
(2, 8) => AppColors.contentColorYellow.withAlpha(100),
_ => throw Error(),
};
return bgColor;
},
getTooltipItems: (ScatterSpot touchedBarSpot) {
return ScatterTooltipItem(
'X: ',
Expand Down
30 changes: 22 additions & 8 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class BarTouchTooltipData with EquatableMixin {
/// if [BarTouchData.handleBuiltInTouches] is true,
/// [BarChart] shows a tooltip popup on top of rods automatically when touch happens,
/// otherwise you can show it manually using [BarChartGroupData.showingTooltipIndicators].
/// Tooltip shows on top of rods, with [tooltipBgColor] as a background color,
/// Tooltip shows on top of rods, with [getTooltipColor] as a background color,
/// and you can set corner radius using [tooltipRoundedRadius].
/// If you want to have a padding inside the tooltip, fill [tooltipPadding],
/// or If you want to have a bottom margin, set [tooltipMargin].
Expand All @@ -692,21 +692,20 @@ class BarTouchTooltipData with EquatableMixin {
/// you can set [fitInsideHorizontally] true to force it to shift inside the chart horizontally,
/// also you can set [fitInsideVertically] true to force it to shift inside the chart vertically.
BarTouchTooltipData({
Color? tooltipBgColor,
double? tooltipRoundedRadius,
EdgeInsets? tooltipPadding,
double? tooltipMargin,
FLHorizontalAlignment? tooltipHorizontalAlignment,
double? tooltipHorizontalOffset,
double? maxContentWidth,
GetBarTooltipItem? getTooltipItem,
GetBarTooltipColor? getTooltipColor,
apekshamehta marked this conversation as resolved.
Show resolved Hide resolved
bool? fitInsideHorizontally,
bool? fitInsideVertically,
TooltipDirection? direction,
double? rotateAngle,
BorderSide? tooltipBorder,
}) : tooltipBgColor = tooltipBgColor ?? Colors.blueGrey.darken(15),
tooltipRoundedRadius = tooltipRoundedRadius ?? 4,
}) : tooltipRoundedRadius = tooltipRoundedRadius ?? 4,
tooltipPadding = tooltipPadding ??
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
tooltipMargin = tooltipMargin ?? 16,
Expand All @@ -715,16 +714,14 @@ class BarTouchTooltipData with EquatableMixin {
tooltipHorizontalOffset = tooltipHorizontalOffset ?? 0,
maxContentWidth = maxContentWidth ?? 120,
getTooltipItem = getTooltipItem ?? defaultBarTooltipItem,
getTooltipColor = getTooltipColor ?? defaultBarTooltipColor,
fitInsideHorizontally = fitInsideHorizontally ?? false,
fitInsideVertically = fitInsideVertically ?? false,
direction = direction ?? TooltipDirection.auto,
rotateAngle = rotateAngle ?? 0.0,
tooltipBorder = tooltipBorder ?? BorderSide.none,
super();

/// The tooltip background color.
final Color tooltipBgColor;

/// Sets a rounded radius for the tooltip.
final double tooltipRoundedRadius;

Expand Down Expand Up @@ -761,10 +758,12 @@ class BarTouchTooltipData with EquatableMixin {
/// The tooltip border color.
final BorderSide tooltipBorder;

/// Retrieves data for setting background color of the tooltip.
final GetBarTooltipColor getTooltipColor;

/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
tooltipBgColor,
tooltipRoundedRadius,
tooltipPadding,
tooltipMargin,
Expand All @@ -776,6 +775,7 @@ class BarTouchTooltipData with EquatableMixin {
fitInsideVertically,
rotateAngle,
tooltipBorder,
getTooltipColor,
];
}

Expand Down Expand Up @@ -845,6 +845,20 @@ class BarTooltipItem with EquatableMixin {
];
}

//// Provides a [Color] to show different background color for each rod
///
/// You can override [BarTouchTooltipData.getTooltipColor], it gives you
/// [group] that touch happened on, then you should and pass your custom [Color] to set background color
/// of tooltip popup.
typedef GetBarTooltipColor = Color Function(
BarChartGroupData group,
);

/// Default implementation for [BarTouchTooltipData.getTooltipColor].
Color defaultBarTooltipColor(BarChartGroupData group) {
return Colors.blueGrey.darken(15);
}

/// Holds information about touch response in the [BarChart].
///
/// You can override [BarTouchData.touchCallback] to handle touch events,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
bottomLeft: radius,
bottomRight: radius,
);
_bgTouchTooltipPaint.color = tooltipData.tooltipBgColor;

/// set tooltip's background color for each rod
_bgTouchTooltipPaint.color = tooltipData.getTooltipColor(showOnBarGroup);

final rotateAngle = tooltipData.rotateAngle;
final rectRotationOffset =
Expand Down
27 changes: 21 additions & 6 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ class LineTouchTooltipData with EquatableMixin {
/// if [LineTouchData.handleBuiltInTouches] is true,
/// [LineChart] shows a tooltip popup on top of spots automatically when touch happens,
/// otherwise you can show it manually using [LineChartData.showingTooltipIndicators].
/// Tooltip shows on top of spots, with [tooltipBgColor] as a background color,
/// Tooltip shows on top of spots, with [getTooltipColor] as a background color,
/// and you can set corner radius using [tooltipRoundedRadius].
/// If you want to have a padding inside the tooltip, fill [tooltipPadding],
/// or If you want to have a bottom margin, set [tooltipMargin].
Expand All @@ -1237,7 +1237,6 @@ class LineTouchTooltipData with EquatableMixin {
/// you can set [fitInsideHorizontally] true to force it to shift inside the chart horizontally,
/// also you can set [fitInsideVertically] true to force it to shift inside the chart vertically.
const LineTouchTooltipData({
this.tooltipBgColor = const Color.fromRGBO(96, 125, 139, 1),
this.tooltipRoundedRadius = 4,
this.tooltipPadding =
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
Expand All @@ -1246,16 +1245,14 @@ class LineTouchTooltipData with EquatableMixin {
this.tooltipHorizontalOffset = 0,
this.maxContentWidth = 120,
this.getTooltipItems = defaultLineTooltipItem,
this.getTooltipColor = defaultLineTooltipColor,
this.fitInsideHorizontally = false,
this.fitInsideVertically = false,
this.showOnTopOfTheChartBoxArea = false,
this.rotateAngle = 0.0,
this.tooltipBorder = BorderSide.none,
});

/// The tooltip background color.
final Color tooltipBgColor;

/// Sets a rounded radius for the tooltip.
final double tooltipRoundedRadius;

Expand Down Expand Up @@ -1292,10 +1289,12 @@ class LineTouchTooltipData with EquatableMixin {
/// The tooltip border color.
final BorderSide tooltipBorder;

// /// Retrieves data for setting background color of the tooltip.
final GetLineTooltipColor getTooltipColor;

/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
tooltipBgColor,
tooltipRoundedRadius,
tooltipPadding,
tooltipMargin,
Expand All @@ -1308,6 +1307,7 @@ class LineTouchTooltipData with EquatableMixin {
showOnTopOfTheChartBoxArea,
rotateAngle,
tooltipBorder,
getTooltipColor,
];
}

Expand Down Expand Up @@ -1336,6 +1336,21 @@ List<LineTooltipItem> defaultLineTooltipItem(List<LineBarSpot> touchedSpots) {
}).toList();
}

//// Provides a [Color] to show different background color for each touched spot
///
/// You can override [LineTouchTooltipData.getTooltipColor], it gives you
/// [touchedSpot] object that touch happened on, then you should and pass your custom [Color] list
/// (length should be equal to the [touchedSpots.length]), to set background color
/// of tooltip popup.
typedef GetLineTooltipColor = Color Function(
LineBarSpot touchedSpot,
);

/// Default implementation for [LineTouchTooltipData.getTooltipColor].
Color defaultLineTooltipColor(LineBarSpot touchedSpot) {
return Colors.blueGrey.darken(15);
}

/// Represent a targeted spot inside a line bar.
class LineBarSpot extends FlSpot with EquatableMixin {
/// [bar] is the [LineChartBarData] that this spot is inside of,
Expand Down
10 changes: 9 additions & 1 deletion lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,15 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
bottomLeft: radius,
bottomRight: radius,
);
_bgTouchTooltipPaint.color = tooltipData.tooltipBgColor;

var topSpot = showingTooltipSpots.showingSpots[0];
for (final barSpot in showingTooltipSpots.showingSpots) {
if (barSpot.y > topSpot.y) {
topSpot = barSpot;
}
}

_bgTouchTooltipPaint.color = tooltipData.getTooltipColor(topSpot);

final rotateAngle = tooltipData.rotateAngle;
final rectRotationOffset =
Expand Down
Loading