flutter - 当 defaultRender 设置为非常基本的 ArcRendererConfig() 时,Flutter GoogleChart 饼图不呈现
问题描述
使用以下 PieChart 小部件按预期显示图表。
class ABCPieChart extends StatefulWidget {
@override
_ABCPieChartState createState() => _ABCPieChartState();
}
class _TABCPieChartState extends State<ABCPieChart> {
List<charts.Series<ChartEntity, String>> _entities = List();
_initData() {
var values = [
ChartEntity("Food", 30, Colors.greenAccent),
ChartEntity("Clothing", 30, Colors.cyan),
ChartEntity("Fashion", 20, Colors.red),
ChartEntity("Gadgets", 20, Colors.blue),
];
_entities.add(charts.Series(
data: values,
domainFn: (ChartEntity entity, _) => entity.title,
measureFn: (ChartEntity entity, _) => entity.percentage,
colorFn: (ChartEntity entity, _) =>
charts.ColorUtil.fromDartColor(entity.color),
id: "random chart",
labelAccessorFn: (ChartEntity entity, _) => "${entity.percentage}"));
}
@override
void initState() {
super.initState();
_entities = List<charts.Series<ChartEntity, String>>();
_initData();
}
@override
Widget build(BuildContext context) {
return Container(
height: 400.0,
width: 400,
child: charts.PieChart(
_entities,
animate: true,
animationDuration: Duration(milliseconds: 500),
),
);
}
}
但是当我尝试将其自定义为甜甜圈形状时,即使添加了一个非常基本defaultRenderer
的,图表也不再呈现在屏幕上。
class ABCPieChart extends StatefulWidget {
@override
_ABCPieChartState createState() => _ABCPieChartState();
}
class _TABCPieChartState extends State<ABCPieChart> {
List<charts.Series<ChartEntity, String>> _entities = List();
_initData() {
var values = [
ChartEntity("Food", 30, Colors.greenAccent),
ChartEntity("Clothing", 30, Colors.cyan),
ChartEntity("Fashion", 20, Colors.red),
ChartEntity("Gadgets", 20, Colors.blue),
];
_entities.add(charts.Series(
data: values,
domainFn: (ChartEntity entity, _) => entity.title,
measureFn: (ChartEntity entity, _) => entity.percentage,
colorFn: (ChartEntity entity, _) =>
charts.ColorUtil.fromDartColor(entity.color),
id: "random chart",
labelAccessorFn: (ChartEntity entity, _) => "${entity.percentage}"));
}
@override
void initState() {
super.initState();
_entities = List<charts.Series<ChartEntity, String>>();
_initData();
}
@override
Widget build(BuildContext context) {
return Container(
height: 400.0,
width: 400,
child: charts.PieChart(
_entities,
animate: true,
animationDuration: Duration(milliseconds: 500),
defaultRenderer: charts.ArcRendererConfig(),
),
);
}
}
即使我在这里复制并粘贴来自 google sample 的代码,它也不会呈现。(在 hotreload、Hotrestart 和 Coldrestart 中都没有)
此问题仅适用于PieChart and ArcRendererConfig.
BarChart
正常BarRendererConfig
工作
我认为这可能是设置问题,或者可能错过了一个非常小但至关重要的东西,有人知道可能出了什么问题吗?
我已经在 Github 上交叉发布了这个问题,希望这个问题会被 GitHub 和 SO(我就是其中之一)中任何不相交的观众看到。不是为了发送垃圾邮件或惹恼任何人。
解决方案
我得到了(在我的情况下是条形图):
defaultRenderer: new charts.BarRendererConfig(
fillPattern: charts.FillPatternType.solid,
//customRendererId: "id",
barRendererDecorator: charts.BarLabelDecorator(
labelPosition: charts.BarLabelPosition.auto,
labelAnchor: charts.BarLabelAnchor.middle),
cornerStrategy: const charts.ConstCornerStrategy(10),
),
推荐阅读
- java - Datanucleus RDBMS JPA Entitymanager GAE Criteriabuilder 多连接错误 org.datanucleus.store.rdbms.query.QueryToSQLMapper
- python - Brython erreur 使用 brython_stdlib.js 打开
- git - 允许停止将代码直接签入到 VSTS 中的主分支
- azure-cosmosdb - CosmosDB Gremlin:具有指定 ID 或名称的资源已存在
- firebase - 使用 Dart 从 Firebase 读取数据。检索子值
- talend - 如何防止 Talend ESB 在内置的 .kar 文件中包含不需要的库?
- java - 应用于每个输入
- css - $document->addStyleSheet 已弃用
- rest - 在给出 500 作为响应的同时通过测试用例
- dotnetnuke - DNN 重定向到 503 错误页面而不是 404 错误页面