/// You can show some tooltipIndicators (a popup with an information)
/// on top of each [LineChartBarData.spots] using [showingTooltipIndicators],
/// just put line indicator number and spots indices you want to show it on top of them.
final List<ShowingTooltipIndicators> showingTooltipIndicators;
我发现了这个,但我不明白我应该做什么。 我试图显示实际的数值,而不仅仅是工具提示中的点的 y 值。 它说我可以在每个点的顶部使用 ShowingTooptipIndicators,
lineBarsData: [
LineChartBarData(
spots: [
FlSpot(1, (double.parse(number[21])-50)/25+1),
FlSpot(5, (double.parse(number[13])-50)/25+1),
FlSpot(9, (double.parse(number[5])-50)/25+1),
],
isCurved: true,
colors: gradientColors,
barWidth: 4,
isStrokeCapRound: true,
dotData: FlDotData(
show: false,
),
也许在这里的某个地方,但怎么办?
class ShowingTooltipIndicators with EquatableMixin {
/// Determines in which line these tooltips should be shown.
final int lineIndex;
/// Determines the spots that each tooltip should be shown.
final List<LineBarSpot> showingSpots;
/// [LineChart] shows some tooltips over each [LineChartBarData],
/// [lineIndex] determines the index of [LineChartBarData],
/// and [showingSpots] determines in which spots this tooltip should be shown.
ShowingTooltipIndicators(int lineIndex, List<LineBarSpot> showingSpots)
: lineIndex = lineIndex,
showingSpots = showingSpots;
我想我可以通过更改 lineIndex 来显示实际的数值,但仍然不知道在哪里输入它们。
感谢您的阅读,我会等待您的建议:)
最佳答案
只需这样添加即可,
BarChartGroupData(x: 1, barsSpace: 2,
showingTooltipIndicators: [0],
barRods: [
BarChartRodData(
y: 30,
rodStackItems: [
BarChartRodStackItem(15, 30, AppColor.barBlue),
BarChartRodStackItem(0, 15, AppColor.pink),
],
width: barWidth,
borderRadius: const BorderRadius.all(Radius.zero)),
]),
如果您想设计特定的工具提示,请在 TouchTooltipData 中使用它, (遵循这种格式 -> BarChart-> BarChartData-> barTouchData: BarTouchData->touchTooltipData-> BarTouchTooltipData-> getTooltipItem)
getTooltipItem: (
BarChartGroupData group,
int groupIndex,
BarChartRodData rod,
int rodIndex,
) {
return BarTooltipItem(
rod.y.round().toString(),
TextStyle(
color: Colors.black,
fontSize: 8.0.sp,
),
);
},
关于android - 如何使用 fl_chart 显示工具提示指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64749579/