chart_flutter:显示相应x轴值波动的y轴值 [英] charts_flutter: Show y-axis value for corresponding x-axis value flutter
问题描述
我试图在我的Flutter应用中显示时间序列图.问题是当我单击x轴上的日期时,相应的y值未显示在y轴上.我在文档中进行了详尽的搜索,但没有提供像这样的示例.我需要做些什么?
I am trying to display a time series chart in my flutter app. The problem is when I click on a date on the x-axis, the corresponding y-value is not displayed on the y-axis. I searched intensively in the documentation, but there is no example provided like this. What do I need to do differently?
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,
),
],
);
}
}
不好意思,我看错了你的问题.
Excuse me, I misread your question.
要在y轴上显示值,我认为您必须创建自己的 LinePointHighlighter
或 SymbolRenderer
才能传递LinePointHighlighter.两者都要求您在图表的 canvas
上绘画.
To show the values on the y-axis I think you will have to create your own LinePointHighlighter
, or SymbolRenderer
to pass your LinePointHighlighter. Both require you to paint on the chart's canvas
.
使用 SelectionModelConfig
获取要显示的选定值.请参阅: https://google.github.io/charts/flutter/example/行为/selection_callback_example
Use SelectionModelConfig
to get the selected value you want to show. See: https://google.github.io/charts/flutter/example/behaviors/selection_callback_example
我自己还没有做过,但是希望对您有帮助.
I haven't done this myself, but I hope this will help you.
这篇关于chart_flutter:显示相应x轴值波动的y轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!