我正在尝试在Flutter应用中显示时间序列图。问题是当我单击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(),
);
}
}
尝试使用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轴上的值,我认为您必须创建自己的LinePointHighlighter
或SymbolRenderer
才能传递LinePointHighlighter。两者都要求您在图表的canvas
上绘制。
使用SelectionModelConfig
获取要显示的所选值。请参阅:https://google.github.io/charts/flutter/example/behaviors/selection_callback_example
我自己还没有做过,但是希望对您有帮助。