mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
web/chart: fix sample (#909)
This commit is contained in:
@@ -24,11 +24,12 @@ class DonutPieChart extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
DonutPieChart(this.seriesList, {this.animate});
|
||||
const DonutPieChart(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [PieChart] with sample data and no transition.
|
||||
factory DonutPieChart.withSampleData() {
|
||||
return new DonutPieChart(
|
||||
return DonutPieChart(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -40,22 +41,22 @@ class DonutPieChart extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory DonutPieChart.withRandomData() {
|
||||
return new DonutPieChart(_createRandomData());
|
||||
return DonutPieChart(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, int>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new LinearSales(0, random.nextInt(100)),
|
||||
new LinearSales(1, random.nextInt(100)),
|
||||
new LinearSales(2, random.nextInt(100)),
|
||||
new LinearSales(3, random.nextInt(100)),
|
||||
LinearSales(0, random.nextInt(100)),
|
||||
LinearSales(1, random.nextInt(100)),
|
||||
LinearSales(2, random.nextInt(100)),
|
||||
LinearSales(3, random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -67,24 +68,24 @@ class DonutPieChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.PieChart(seriesList,
|
||||
return charts.PieChart(seriesList,
|
||||
animate: animate,
|
||||
// Configure the width of the pie slices to 60px. The remaining space in
|
||||
// the chart will be left as a hole in the center.
|
||||
defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60));
|
||||
defaultRenderer: charts.ArcRendererConfig(arcWidth: 60));
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 100),
|
||||
new LinearSales(1, 75),
|
||||
new LinearSales(2, 25),
|
||||
new LinearSales(3, 5),
|
||||
LinearSales(0, 100),
|
||||
LinearSales(1, 75),
|
||||
LinearSales(2, 25),
|
||||
LinearSales(3, 5),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
Reference in New Issue
Block a user