Charts 为什么我不能在图表中为饼图制作一个类字符串作为域
您好,我正在努力使Piechart基于其 但我只改变了一件事,我改变了Charts 为什么我不能在图表中为饼图制作一个类字符串作为域,charts,flutter,Charts,Flutter,您好,我正在努力使Piechart基于其 但我只改变了一件事,我改变了 final int year 到 但是对于domainFn我得到了这个错误: 我的标签应该是string而不是int,我怎么能做到呢 我的代码: import 'package:charts_flutter/flutter.dart' as charts; import 'package:flutter/material.dart'; class PieOutsideLabelChart extends Stat
final int year
到
但是对于domainFn
我得到了这个错误:
我的标签应该是string而不是int,我怎么能做到呢
我的代码:
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class PieOutsideLabelChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PieOutsideLabelChart(this.seriesList, {this.animate});
factory PieOutsideLabelChart.withSampleData() {
return new PieOutsideLabelChart(
_createSampleData(),
animate: false,
);
}
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
animate: animate,
defaultRenderer: new charts.ArcRendererConfig(arcRendererDecorators: [
new charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition.outside)
]));
}
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales('a long text', 100),
new LinearSales('even longer text', 75),
new LinearSales('i am long text', 25),
new LinearSales('the longest text ever', 5),
];
return [
new charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: data,
labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}',
)
];
}
}
class LinearSales {
final String year;
final int sales;
LinearSales(this.year, this.sales);
}
main(List<String> args) {
runApp(MaterialApp(
title: 'charts',
home: new Scaffold(
appBar: new AppBar(title: new Text("نمودار فلان"),),
body:new ListView(children: <Widget>[
new Card
(child: PieOutsideLabelChart(PieOutsideLabelChart._createSampleData()),)
// ]
// ),
]
)
)
)
);
}
import'包:图表_flatter/flatter.dart'作为图表;
进口“包装:颤振/材料.省道”;
类PieOutsideLabelChart扩展了无状态小部件{
最终清单系列清单;
最后的布尔动画;
PieOutsideLabelChart(this.seriesList,{this.animate});
工厂PieOutsideLabelChart.带采样数据(){
返回新的PieOutsideLabelChart(
_createSampleData(),
动画:假,
);
}
@凌驾
小部件构建(构建上下文){
返回新图表。PieChart(系列列表,
动画制作:动画制作,
defaultRenderer:new charts.ArcRenderConfig(ArcRenderDecorators:[
新图表。ArcLabelDecorator(
labelPosition:图表。ArcLabelPosition。外部)
]));
}
静态列表_createSampleData(){
最终数据=[
新的LinearSales('长文本',100),
新的LinearSales(“更长的文本”,75),
新的LinearSales('我是长文本',25),
新的LinearSales(“有史以来最长的文本”,5),
];
返回[
新图表系列(
id:'销售',
domainFn:(LinearSales sales,)=>sales.year,
measureFn:(LinearSales sales,)=>sales.sales,
数据:数据,
labelAccessorFn:(LinearSales行,)=>'${row.year}:${row.sales}',
)
];
}
}
线性类{
最后一年;
最终销售;
LinearSales(今年,今年,销售);
}
主(列表参数){
runApp(材料应用程序)(
标题:"图表",,
家:新脚手架(
appBar:新appBar(标题:新文本(“appBar”),
正文:新建列表视图(子项:[
新卡
(子项:PieOutsideLabelChart(PieOutsideLabelChart.\u createSampleData()),)
// ]
// ),
]
)
)
)
);
}
非常简单:
再次将年份变量设置为int:
final int year
这里使用toString()
方法:
labelAccessorFn:(LinearSales行,)=>'${row.year.toString()}:${row.sales}',
非常简单:
再次将年份变量设置为int:
final int year
这里使用toString()
方法:
labelAccessorFn:(LinearSales行,)=>'${row.year.toString()}:${row.sales}',
这是语法问题。我的错:D
我应该将我的charts.Series从charts.Series>
更改为charts.Series>
此代码适用于:
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class PieOutsideLabelChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PieOutsideLabelChart(this.seriesList, {this.animate});
factory PieOutsideLabelChart.withSampleData() {
return new PieOutsideLabelChart(
_createSampleData(),
animate: false,
);
}
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
animate: animate,
defaultRenderer: new charts.ArcRendererConfig(arcRendererDecorators: [
new charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition.outside)
]));
}
static List<charts.Series<LinearSales, String>> _createSampleData() {
final data = [
new LinearSales('a long text', 100),
new LinearSales('even longer text', 75),
new LinearSales('i am long text', 25),
new LinearSales('the longest text ever', 5),
];
return [
new charts.Series<LinearSales, String>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: data,
labelAccessorFn: (LinearSales row, _) => '${row.year}',
)
];
}
}
class LinearSales {
final String year;
final int sales;
LinearSales(this.year, this.sales);
}
main(List<String> args) {
runApp(MaterialApp(
title: 'charts',
home: new Scaffold(
appBar: new AppBar(title: new Text("نمودار فلان"),),
body: PieOutsideLabelChart(PieOutsideLabelChart._createSampleData()),)
)
);
}
import'包:图表_flatter/flatter.dart'作为图表;
进口“包装:颤振/材料.省道”;
类PieOutsideLabelChart扩展了无状态小部件{
最终清单系列清单;
最后的布尔动画;
PieOutsideLabelChart(this.seriesList,{this.animate});
工厂PieOutsideLabelChart.带采样数据(){
返回新的PieOutsideLabelChart(
_createSampleData(),
动画:假,
);
}
@凌驾
小部件构建(构建上下文){
返回新图表。PieChart(系列列表,
动画制作:动画制作,
defaultRenderer:new charts.ArcRenderConfig(ArcRenderDecorators:[
新图表。ArcLabelDecorator(
labelPosition:图表。ArcLabelPosition。外部)
]));
}
静态列表_createSampleData(){
最终数据=[
新的LinearSales('长文本',100),
新的LinearSales(“更长的文本”,75),
新的LinearSales('我是长文本',25),
新的LinearSales(“有史以来最长的文本”,5),
];
返回[
新图表系列(
id:'销售',
domainFn:(LinearSales sales,)=>sales.year,
measureFn:(LinearSales sales,)=>sales.sales,
数据:数据,
labelAccessorFn:(LinearSales行,)=>“${row.year}”,
)
];
}
}
线性类{
最后一年;
最终销售;
LinearSales(今年,今年,销售);
}
主(列表参数){
runApp(材料应用程序)(
标题:"图表",,
家:新脚手架(
appBar:新appBar(标题:新文本(“appBar”),
正文:PieOutsideLabelChart(PieOutsideLabelChart.\u createSampleData()),)
)
);
}
这是语法问题。我的错:D
我应该将我的charts.Series从charts.Series>
更改为charts.Series>
此代码适用于:
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class PieOutsideLabelChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PieOutsideLabelChart(this.seriesList, {this.animate});
factory PieOutsideLabelChart.withSampleData() {
return new PieOutsideLabelChart(
_createSampleData(),
animate: false,
);
}
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
animate: animate,
defaultRenderer: new charts.ArcRendererConfig(arcRendererDecorators: [
new charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition.outside)
]));
}
static List<charts.Series<LinearSales, String>> _createSampleData() {
final data = [
new LinearSales('a long text', 100),
new LinearSales('even longer text', 75),
new LinearSales('i am long text', 25),
new LinearSales('the longest text ever', 5),
];
return [
new charts.Series<LinearSales, String>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: data,
labelAccessorFn: (LinearSales row, _) => '${row.year}',
)
];
}
}
class LinearSales {
final String year;
final int sales;
LinearSales(this.year, this.sales);
}
main(List<String> args) {
runApp(MaterialApp(
title: 'charts',
home: new Scaffold(
appBar: new AppBar(title: new Text("نمودار فلان"),),
body: PieOutsideLabelChart(PieOutsideLabelChart._createSampleData()),)
)
);
}
import'包:图表_flatter/flatter.dart'作为图表;
进口“包装:颤振/材料.省道”;
类PieOutsideLabelChart扩展了无状态小部件{
最终清单系列清单;
最后的布尔动画;
PieOutsideLabelChart(this.seriesList,{this.animate});
工厂PieOutsideLabelChart.带采样数据(){
返回新的PieOutsideLabelChart(
_createSampleData(),
动画:假,
);
}
@凌驾
小部件构建(构建上下文){
返回新图表。PieChart(系列列表,
动画制作:动画制作,
defaultRenderer:new charts.ArcRenderConfig(ArcRenderDecorators:[
新图表。ArcLabelDecorator(
labelPosition:图表。ArcLabelPosition。外部)
]));
}
静态列表_createSampleData(){
最终数据=[
新的LinearSales('长文本',100),
新的LinearSales(“更长的文本”,75),
新的LinearSales('我是长文本',25),
新的LinearSales(“有史以来最长的文本”,5),
];
返回[
新图表系列(
id:'销售',
domainFn:(LinearSales sales,)=>sales.year,
measureFn:(LinearSales sales,)=>sales.sales,
数据:数据,
labelAccessorFn:(LinearSales行,)=>“${row.year}”,
)
];
}
}
线性类{
最后一年;
最终销售;
LinearSales(今年,今年,销售);
}
主(列表参数){
runApp(材料应用程序)(
标题:"图表",,
家:新脚手架(
appBar:新appBar(标题:新文本(“appBar”),
正文:PieOutsideLabelChart(PieOutsideLabelChart.\u createSamp
defaultRenderer: new charts.ArcRendererConfig(
arcWidth: 60,
arcRendererDecorators: [new charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition.outside)]
),
String datas(int id,int value){
if(id==0){
return value.toString()+":RT";
}else if(id==1){
return value.toString()+":OT";
}
else if(id==2){
return value.toString()+":IT";
}
return [
new charts.Series<VfmProductivityPie, int>(
id: 'Sales',
domainFn: (VfmProductivityPie sales, _) => sales.id,
measureFn: (VfmProductivityPie sales, _) => sales.value,
data: data,
labelAccessorFn: (VfmProductivityPie row, _) =>
// print('object'),
//'${row.id}r: ${row.value}',
datas(row.id,row.value)
)
];