【问题标题】:charts_flutter: Show y-axis value for corresponding x-axis value flutterchart_flutter:显示对应x轴值flutter的y轴值
【发布时间】:2020-03-31 11:09:05
【问题描述】:

我正在尝试在我的颤振应用中显示时间序列图表。问题是当我单击 x 轴上的日期时,相应的 y 值不会显示在 y 轴上。我在文档中进行了深入搜索,但没有提供这样的示例。我需要做些什么不同的事情?

class MyLineChart extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  MyLineChart(this.seriesList, {this.animate});

  @override
  Widget build(BuildContext context) {
    return new charts.TimeSeriesChart(
      seriesList,
      animate: animate,
      dateTimeFactory: const charts.LocalDateTimeFactory(),
    );
  }
}

【问题讨论】:

    标签: flutter dart google-visualization


    【解决方案1】:

    试试这个,使用LinePointHighlighter:

    class MyLineChart extends StatelessWidget {
      final List<charts.Series> seriesList;
      final bool animate;
    
      MyLineChart(this.seriesList, {this.animate});
    
      @override
      Widget build(BuildContext context) {
        return new charts.TimeSeriesChart(
          seriesList,
          animate: animate,
          dateTimeFactory: const charts.LocalDateTimeFactory(),
          behaviors: [
            LinePointHighlighter(
              drawFollowLinesAcrossChart: true,
              showHorizontalFollowLine: LinePointHighlighterFollowLineType.all,
            ),
          ],
        );
      }
    }
    

    编辑: 对不起,我看错了你的问题。

    要在 y 轴上显示值,我认为您必须创建自己的 LinePointHighlighterSymbolRenderer 以传递您的 LinePointHighlighter。两者都要求您在图表的canvas 上作画。

    使用SelectionModelConfig 获取要显示的选定值。见:https://google.github.io/charts/flutter/example/behaviors/selection_callback_example

    我自己没有这样做,但我希望这会对你有所帮助。

    【讨论】:

    • 感谢您的回复。您的答案仅显示虚线。我还需要在 y 轴上显示这些值。知道该怎么做吗?
    • @Er1 hi.. 我想试试你的代码,你有任何示例如何创建LinePointHighlighter 吗?
    • @uyhaW 希望这会对您有所帮助gist.github.com/cirediew/c22b2736028ef06b10b934d6c863664d
    • @Er1 非常感谢你的帮助,我会试试的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    相关资源
    最近更新 更多