简体   繁体   English

Flutter syncfusion Linechart 重新绘制开始和结束系列数据之间的线

[英]Flutter syncfusion Linechart re-draw line between beginning and ending series data

I use syncfusion chart for flutter.我使用 flutter 的同步融合图表。 I have json data on php api at my server.我的服务器上有关于 php api 的 json 数据。 I had this data in flutter api connect.我在 flutter api 连接中有这些数据。

My json data structure is like this:我的 json 数据结构是这样的:

  {
  "tablo": "neyzi",
  "cinsiyet": "erkek",
  "boy": {
    "P3": [
      {
        "0.0": 45.9,
        "3.0": 56.2,
        "6.0": 62.8,
        "9.0": 67.4,
        "12.0": 70.8,
        "15.0": 73.8,
        "18.0": 76.4
        }
    ],
   
  },
  
}

I use this code for prepare data for chart:我使用此代码为图表准备数据:

    import 'package:flutter/material.dart';
import 'package:pediatrirutinmobil/pers_chart/chart_olcumdizisi.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'chart_api.dart';


class PersentilChartRepository{
  static PersentilChartApiClient _persentilchartApiClient = PersentilChartApiClient();

  static List<OlcumDizisi> _p3 =[];
  

  static Future apiden_data_getir ()async{
    return await _persentilchartApiClient.veriyigetir();
  }

  static Future<List<OlcumDizisi>> persentilListesi ()async{

  }



  static List boyListesi() {

  

    apiden_data_getir().then((value) async{
  
      var P3e = await value.boy.P3[0];
    

    for (final mapEntry in P3e.entries) {

        final key = await double.parse(mapEntry.key.toString());
        final double value = await double.parse(mapEntry.value.toString());
        if (key<=limit){
       _p3.add(OlcumDizisi(key, value));
      }
      }
      
     
    // _p3.addAll([OlcumDizisi(6,60),OlcumDizisi(7, 80),OlcumDizisi(10, 90)]);
      */
    } );

       List<ChartSeries<OlcumDizisi,double>> chartSeries =  [
       new LineSeries<OlcumDizisi, double>(
         name: 'P3',
         xValueMapper: (OlcumDizisi olcum, _) => olcum.yasay,
         yValueMapper: (OlcumDizisi olcum, _) => olcum.olcum,
         dataSource: _p3,
         color: Colors.red,
         width: 0.75,
         
       )
        
     ];
      
    return  chartSeries;
  }

}


class OlcumDizisi {
  final double yasay;
  final double olcum;

  OlcumDizisi(this.yasay, this.olcum);
}

And I use chart page like this:我使用这样的图表页面:

import 'dart:core';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:pediatrirutinmobil/pers_chart/chart_repo.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

class StackedAreaLineChart extends StatefulWidget {

  @override
  State<StackedAreaLineChart> createState() => _StackedAreaLineChartState();
}

class _StackedAreaLineChartState extends State<StackedAreaLineChart> {
  List _charset;
  @override
  void initState() async{
     _charset = await PersentilChartRepository.boyListesi();
     setState(() {
       
     });
    // TODO: implement initState
    super.initState();
  }
  @override
  void dispose() {
    _charset;
    // TODO: implement dispose
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
             body: SafeArea(
               child: Center(
                 child: Container(
                  
                   child:  SfCartesianChart(
                       primaryXAxis: CategoryAxis(),
                       primaryYAxis: NumericAxis(
                         numberFormat: NumberFormat.decimalPattern()
                       ),
                       // Chart title
                       title: ChartTitle(text: 'TITLE'),
                       // Enable legend
                       legend: Legend(isVisible: true),
                       // Enable tooltip
                       tooltipBehavior: TooltipBehavior(enable: true),
                       series:_charset,
                       enableSideBySideSeriesPlacement: false,

                   ),
                 ),
               ),
             ),
    );
  }
}

so after then all of this page my chart build graphic but if I back another page and reopen chart page Linechart re-build new line beginning point and ending point.所以在那之后所有这个页面我的图表构建图形但是如果我返回另一个页面并重新打开图表页面 Linechart 重新构建新的线起点和终点。 like this:像这样:

this这个

and this和这个

If i use static List data in chart page its perfect but i use static data in future code like this如果我在图表页面中使用 static 列出数据是完美的,但我在以后的代码中使用 static 数据这样

 apiden_data_getir().then((value) async{
      
       _p3.addAll([OlcumDizisi(6,60),OlcumDizisi(7, 80),OlcumDizisi(10, 90)]);
          
        } );

final result same...最终结果一样...

is there any idea.有什么想法吗?

If you have different solution binding api line chart so I thank you for it.如果您有不同的解决方案绑定 api 折线图,谢谢。

The reported issue regarding line redrawn from start and endpoint of the line series is not reproduced at our end.关于从线系列的起点和终点重新绘制的线的报告问题在我们结束时没有复制。 We have used the code snippet provided in the query even though the issue didn't get reproduced.我们已经使用了查询中提供的代码片段,即使该问题没有被重现。 We have attached the sample for your reference.我们附上了样品供您参考。 Can you please ensure whether data in your database is correct and also ensure proper data is bind to the chart, since we suspect that the first data is stored again, so the line gets closed.请您确保您的数据库中的数据是否正确,并确保正确的数据绑定到图表,因为我们怀疑第一个数据再次存储,因此该行被关闭。 Since we are not aware of your exact data source and the issue is not replicated with the provided code, kindly get back to us by replicating your scenario with the attached sample.由于我们不知道您的确切数据源,并且提供的代码未复制问题,请通过使用随附的示例复制您的方案与我们联系。

Screenshot https://i.stack.imgur.com/uy4rD.png截图https://i.stack.imgur.com/uy4rD.png

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/i364893-1745166518.zip样品: https://www.syncfusion.com/downloads/support/directtrac/general/ze/i364893-1745166518.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM