android - 如何使用 fl_chart 显示工具提示指示器?

标签 android ios flutter dart

 /// 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/

相关文章:

ios - 汉化

ios - 在 iOS 7 中的导航栏按钮项目上使用 NSShadow

flutter 卡住 :Could not generate `toJson` code for `data` because of type

Android 跨 Activity 维护掩码

java - 在自定义适配器 ListView 中检查时 toast

android - 如何检查用户是否有订阅(Android 应用内计费)?

flutter - 如何给FadeInImage.assetNetwork图像中的圆角矩形形状 flutter 打?

Android QuickBlox - 用户必须有联系人列表

ios - 查看 Controller 更改选项卡栏图标和操作

flutter - 我无法从 cloud firestore 访问文档字段并在 flutter 的 statefulwidget 类中显示它