【问题标题】:Flutter PieChart Labels --how to make it worksFlutter PieChart 标签——如何让它工作
【发布时间】:2021-12-22 10:01:51
【问题描述】:

我试图让我的 PieChart 标签可见,但是在设置 arcRenderDecorators 之后它就出现了

  1. RenderBox 未布置:ChartContainerRenderObject#1bf0d NEEDS-PAINT 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
  2. RenderBox 未布置:RenderPointerListener#5ff88 需要-绘制需要-合成-位-更新 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
  3. RenderBox 未布置:RenderSemanticsGestureHandler#4a473 需要-绘制需要-合成-位-更新 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
  4. RenderBox 未布置:ChartContainerRenderObject#1bf0d 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize' 问题。

我必须使用什么样的小部件才能做到这一点。请帮忙。

 final List<DeveloperSeries> data = [

   DeveloperSeries(
     year: "2017",
     developers: 40000,
     barColor: charts.ColorUtil.fromDartColor(Colors.blue),
   ),
   DeveloperSeries(
     year: "2019",
     developers: 40000,
     barColor: charts.ColorUtil.fromDartColor(Colors.blue),
   ),
   DeveloperSeries(
     year: "2020",
     developers: 35000,
     barColor: charts.ColorUtil.fromDartColor(Colors.blue),
   ),
   DeveloperSeries(
     year: "2021",
     developers: 45000,
     barColor: charts.ColorUtil.fromDartColor(Colors.blue),
   ),
 ];

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: Center(
       child: DeveloperChart(
         data: data,
       )
     ),
   );
 }
}
class DeveloperChart extends StatelessWidget {
 final List<DeveloperSeries> data;

 DeveloperChart({required this.data});

 @override
 Widget build(BuildContext context) {
   List<charts.Series<DeveloperSeries, String>> series = [
     charts.Series(
       id: "developers",
       data: data,
       domainFn: (DeveloperSeries series, _) => series.year,
       measureFn: (DeveloperSeries series, _) => series.developers,
       colorFn: (DeveloperSeries series, _) => series.barColor,
       labelAccessorFn: (DeveloperSeries row, _) => row.year,
     )
   ];

   return Container(
       height: 500,
       width: 500,
       child: Card(
         child: Padding(
           padding: const EdgeInsets.all(9.0),
           child: Column(
               children: <Widget>[
                 Text(
                   "Yearly Growth in the Flutter Community",
                   style: Theme
                       .of(context)
                       .textTheme
                       .bodyText2,
                 ),
                 Expanded(
                     child: charts.PieChart(series, animate: true,
                         defaultRenderer: charts.ArcRendererConfig(
                             arcRendererDecorators: [
                               charts.ArcLabelDecorator(
                                   labelPosition: charts.ArcLabelPosition
                                       .outside)
                             ])
                     )
                 )
               ]
           ),
         ),
       )
   );
 }
}```

【问题讨论】:

    标签: flutter charts


    【解决方案1】:

    同样的问题,我通过替换解决了:

    charts.PieChart(
    
    

    与:

    charts.PieChart<String>(
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2017-12-01
      • 2021-12-01
      • 2020-06-05
      相关资源
      最近更新 更多