Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何防止图表抖动中setState()上的指示点消失_Flutter_Dart_Charts - Fatal编程技术网

Flutter 如何防止图表抖动中setState()上的指示点消失

Flutter 如何防止图表抖动中setState()上的指示点消失,flutter,dart,charts,Flutter,Dart,Charts,在图表内更新数据系列时,颤振时间序列显示点消失。建议了一个可能的解决方法,但到目前为止,我还没有能够实现它,因为解释中没有完整的示例。有没有人能举例说明他们能做到这一点?具体地说,我试图在更新文本小部件的同时保持图形线上的指示点 TimeSeriesChart的代码: new charts.TimeSeriesChart( getSeries(阅读), dateTimeFactory:新图表。UTCDateTimeFactory(), 动画:假, 选择型号:[ 新建charts.Selectio

在图表内更新数据系列时,颤振时间序列显示点消失。建议了一个可能的解决方法,但到目前为止,我还没有能够实现它,因为解释中没有完整的示例。有没有人能举例说明他们能做到这一点?具体地说,我试图在更新
文本
小部件的同时保持图形线上的指示点

TimeSeriesChart的代码:

new charts.TimeSeriesChart(
getSeries(阅读),
dateTimeFactory:新图表。UTCDateTimeFactory(),
动画:假,
选择型号:[
新建charts.SelectionModelConfig(
changedListener:_onSelectionChanged,
)
],
行为:[
新图表。LinePointHighlighter(
defaultRadiusPx:20.0,
RadiusAddingPx:20.0,
showHorizontalFollowLine:
charts.LinePointHighlighterFollowLineType.nearest,
showVerticalFollowLine:
charts.LinePointHighlighterFollowLineType.nearest
),
新图表。选择最近的(
eventTrigger:charts.SelectionTrigger.Tap和Drag
)
],
主要测量轴:。。。
域轴:。。。
然后选择的代码更改了:

_onSelectionChanged(charts.SelectionModel model) {
  final selectedDatum = model.selectedDatum;

  DateTime time;
  final measures = <String, num>{};
  num value;
  if (selectedDatum.isNotEmpty) {
    time = selectedDatum.first.datum.time;
    value = selectedDatum.first.datum.value;

    selectedDatum.forEach((charts.SeriesDatum datumPair) {
      measures[datumPair.series.displayName] = datumPair.datum.value;
      if (!datumPair.series.id.contains("min") && !datumPair.series.id.contains("max"))
        value = datumPair.datum.value;
    });
  }
  setState(() {
    _time = time;
    _measures = measures;
    _value = value; // This is the value that is used within the `Text` widget
  });
}
\u选项已更改(charts.SelectionModel){
最终选定数据=模型。选定数据;
日期时间;
最后措施={};
数值;
if(selectedDatum.isNotEmpty){
时间=所选的datum.first.datum.time;
值=所选的datum.first.datum.value;
已选择的数据格式((charts.seriesdatam datumPair){
度量值[datumPair.series.displayName]=datumPair.datum.value;
如果(!datumPair.series.id.contains(“最小”)和(!datumPair.series.id.contains(“最大”))
值=datumPair.datum.value;
});
}
设置状态(){
_时间=时间;
_措施=措施;
_value=value;//这是“Text”小部件中使用的值
});
}
我是如何让它工作的:

class InnerStatefulWidget extends StatefulWidget {
    final List<charts.Series<T, DateTime>> seriesList; //where T is the class used to create the series

    InnerStatefulWidget(this.seriesList);

    factory InnerStatefulWidget.withSampleData(D apiData) { // where D is the class for the data from API
        return new InnerStatefulWidget(
          _createSeriesData(apiData) // the function that receives data from the API and converts it into series
        );
    }

    static List<charts.Series<T, DateTime>> _createSeriesData(D apiData) {
        return new charts.Series<T, DateTime>(
            id: CHART_ID,
            domainFn: (T x, _) => x.dateTime,
            measureFn: (T x, _) => x.value,
            data: apiData));
     }

    @override
    _InnerStatefulWidgetState createState() => _InnerStatefulWidgetState();
}

class _InnerStatefulWidgetState extends State<InnerStatefulWidget> {
    @override
    Widget build(BuildContext context) {
        return new charts.TimeSeriesChart(
          widget.seriesList,
          ...
          selectionModels: [
            new charts.SelectionModelConfig(
              type: charts.SelectionModelType.info,
              changedListener: _onSelectionChanged,
            )
          ],
        );
    }

    void _onSelectionChanged(charts.SelectionModel model) {
        ...
    }
}

class OuterStatefulWidget extends StatefulWidget {
  D apiData;

  OuterStatefulWidget(this.apiData);

  @override
  _OuterStatefulWidgetState createState() => _OuterStatefulWidgetState();
}

class _OuterStatefulWidgetState extends State<OuterStatefulWidget> {
  @override
  Widget build(BuildContext context) {
    return InnerStatefulWidget.withSampleData(widget.apiData); 
  }
}
类InnerStatefulWidget扩展了StatefulWidget{
final List seriesList;//其中T是用于创建序列的类
InnerStatefulWidget(this.seriesList);
factory InnerStatefulWidget.withSampleData(D apiData){//其中D是来自API的数据的类
返回新的InnerStatefulWidget(
_createSeriesData(apiData)//从API接收数据并将其转换为序列的函数
);
}
静态列表_createSeriesData(apiData){
返回新图表。系列(
id:CHART_id,
域fn:(tx,)=>x.dateTime,
measureFn:(tx,)=>x.value,
数据:apiData);
}
@凌驾
_InnerStatefulWidgetState createState()=>\u InnerStatefulWidgetState();
}
类_InnerStatefulWidgetState扩展状态{
@凌驾
小部件构建(构建上下文){
返回新图表。TimeSeriesChart(
widget.seriesList,
...
选择型号:[
新建charts.SelectionModelConfig(
类型:charts.SelectionModelType.info,
changedListener:_onSelectionChanged,
)
],
);
}
void\u onselection已更改(charts.SelectionModel){
...
}
}
类OuterStatefulWidget扩展StatefulWidget{
APID数据;
OuterStatefulWidget(this.apiData);
@凌驾
_OuterStatefulWidgetState createState()=>\u OuterStatefulWidgetState();
}
类_OuterStatefulWidgetState扩展状态{
@凌驾
小部件构建(构建上下文){
返回InnerStatefulWidget.with采样数据(widget.apiData);
}
}

您找到解决方案了吗?我也有这个问题。。。