我想把图表放在我的卡片上,图表的示例代码只是用来链接的https://google.github.io/charts/flutter/example/line_charts/points.
下面的代码是我的代码。
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 0),
child: Card(
elevation: 0.333,
child: HistoryChart, <--- I want to put chart here
)
)
但我得到了参数类型"type"无法分配给参数类型"Widget"错误。
我应该更改什么才能正确地处理此代码?
从line_charts包导入PointsLineChart类之后
您将Type放在Widget的位置
如果你想在图表中显示简单的数据,试试这个:
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 0),
child: Card(
elevation: 0.333,
child: Container(
child: PointsLineChart.withSampleData(),
height: 250,
),
),
);
如果你想要真实的数据,试试这个:
import 'package:charts_flutter/flutter.dart' as charts;
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 0),
child: Card(
elevation: 0.333,
child: Container(height: 250,
child: PointsLineChart(
getData(),
// Disable animations for image tests.
animate: false,
),
),
)));
List<charts.Series<LinearSales, int>> getData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: data,
)
];}