показывать трепетные графики, передавая пользовательский список - PullRequest
0 голосов
/ 28 января 2020

Я хочу показать график, передавая пользовательский список созданному мною классу.
DailyCountModel содержит 3 параметра, первый строковый параметр - это статус, следующая строка -
тип счета, а последняя - тип int count. я хочу показать линии на моем графике, передав параметры графа на график в FlSpot

я добавил класс модели и основной класс для справки

            class DailyGraphDataModel {
                String mid;
                String cardType;
                String totalcount; 
              DailyGraphDataModel({
                 this.mid,
                 this.cardType,
                 this.totalcount, 
               }); 
                }

          List<DailyCountModel> list = List()
           @override
            Widget build(BuildContext context) {
           return Scaffold(
           child: Container(
                  margin: EdgeInsets.fromLTRB(15, 5, 15, 10),
                  width: double.infinity,
                  decoration: BoxDecoration(
                      borderRadius: const BorderRadius.all(
                        Radius.circular(18),
                      ),
                      color: const Color(0xffbddbff).withOpacity(0.3)),
                  child: Padding(
                    padding: EdgeInsets.all(20),
                    child: LineChart(
                      Graph.mainData(list),
                    ),
                  ),
                ),
               ),
              }


           class Graph{
           static LineChartData mainData(List<DailyCountModel> list) { 
            LineChartData(     
            gridData:(),
            titlesData:(),
            borderData:(),
            lineBarsData: [
            LineChartBarData(
            spots:[
            //Want to pass data here 
            FlSpot(0, 50),
            FlSpot(1, 100),
            FlSpot(2, 140),
            FlSpot(3, 185),
            FlSpot(4, 238),
            FlSpot(5, 442),
            FlSpot(6, 451),
            FlSpot(7, 652),
            FlSpot(8, 701),
           ],
           isCurved: true,
           colors: gradientColors,
           barWidth: 2,
           isStrokeCapRound: true,
           dotData: const FlDotData(
           show: false,
           ),
           belowBarData: BarAreaData(
           show: true,
           colors:
            gradientColors.map((color) => color.withOpacity(0.3)).toList(),
          ),
        ),
       ],
      );
     }
    }

1 Ответ

0 голосов
/ 25 марта 2020

Просто создайте учетную запись, чтобы помочь вам:)

//method used to build spots from array parameter
getCurrencyHistoryData(List history) {
List<FlSpot> widgets = [];
   var i = 0;
   history.forEach((item) {
     widgets.add(FlSpot(i.toDouble(), (double.parse(item['rate']) ?? 0.00)));
     i++;
   });

   return widgets;
 }

//here is the spots in the widget
spots: getCurrencyHistoryData(history),

Надеюсь, я не опоздал. Лучший

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...