【问题标题】:How to add label to flutter chart?如何为颤动图表添加标签?
【发布时间】:2019-08-31 09:34:23
【问题描述】:

我尝试使用 charts_flutter: ^0.6.0 依赖项, 图表工作得很好。

但我想在图表中为 x 轴和 y 轴添加标签。 在这张图片中标注评分和条目数。
charts.BarChart(
              _seriesData,
              animate: true,
              behaviors: [new charts.SeriesLegend()],
              animationDuration: Duration(seconds: 3),
            )

【问题讨论】:

  • 尝试将您的图表视图与其他两个视图一起包含在底部和一个左侧
  • @ManojPerumarath,颤动图表没有那个 x 和 y 轴标签吗?
  • 不,它没有
  • 好的,就是这样。谢谢你的信息。我将使用其他方式,使用普通文本并旋转它。

标签: android flutter dart


【解决方案1】:

假设在官方文档中没有找到任何解决方案:https://pub.dev/documentation/flutter_charts/latest/

用 Stack Widget 包装该小部件并向其添加一个 Text 小部件:

Stack(
  children: <Widget>[
    AnimatedPositioned(
      // use top,bottom,left and right property to set the location and Transform.rotate to rotate the widget if needed
child : Text("Title comes here"),
duration : Duration(seconds:3),
),
charts.BarChart(
              _seriesData,
              animate: true,
              behaviors: [new charts.SeriesLegend()],
              animationDuration: Duration(seconds: 3),
            ),
]
)

【讨论】:

  • 我用这个做X轴标签;并将底部设置为 0。标签与 x 轴标记(1、2、3 等)重叠。
猜你喜欢
  • 2019-10-19
  • 2014-02-27
  • 2021-09-01
  • 1970-01-01
  • 2020-04-23
  • 2020-04-27
  • 2021-08-11
  • 2022-06-15
  • 1970-01-01
相关资源
最近更新 更多