Fix chart tooltip

This commit is contained in:
Hanh 2021-09-07 12:40:21 +08:00
parent 76a200ebcf
commit c4f7999ec4
1 changed files with 17 additions and 0 deletions

View File

@ -62,6 +62,9 @@ class LineChartTimeSeriesState extends State<LineChartTimeSeries> {
theme.primaryColor,
];
final textStyle = theme.textTheme.bodyText1;
final bgColor = theme.backgroundColor;
return LineChartData(
gridData: FlGridData(
show: true,
@ -131,6 +134,20 @@ class LineChartTimeSeriesState extends State<LineChartTimeSeries> {
),
),
],
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: bgColor,
getTooltipItems: (touchedSpots) =>
touchedSpots.map((LineBarSpot spot) {
final x = spot.x;
final dt = DateTime.fromMillisecondsSinceEpoch(x.toInt() * DAY_MS);
final xdt = DateFormat.Md().format(dt);
final y = spot.y.toStringAsFixed(3);
return LineTooltipItem("$xdt - $y",
textStyle);
}).toList()
)
)
);
}
}