1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-30 19:08:56 +00:00

web/chart: fix sample (#909)

This commit is contained in:
Brett Morgan
2021-10-07 08:10:34 +11:00
committed by GitHub
parent 0fe216a1cf
commit 2d9ba2f9eb
118 changed files with 3655 additions and 3511 deletions

View File

@@ -28,10 +28,11 @@ class DatumLegendOptions extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
DatumLegendOptions(this.seriesList, {this.animate});
const DatumLegendOptions(this.seriesList, {this.animate, Key key})
: super(key: key);
factory DatumLegendOptions.withSampleData() {
return new DatumLegendOptions(
return DatumLegendOptions(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -43,22 +44,22 @@ class DatumLegendOptions extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory DatumLegendOptions.withRandomData() {
return new DatumLegendOptions(_createRandomData());
return DatumLegendOptions(_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,
@@ -70,14 +71,14 @@ class DatumLegendOptions extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.PieChart(
return charts.PieChart(
seriesList,
animate: animate,
// Add the legend behavior to the chart to turn on legends.
// This example shows how to change the position and justification of
// the legend, in addition to altering the max rows and padding.
behaviors: [
new charts.DatumLegend(
charts.DatumLegend(
// Positions for "start" and "end" will be left and right respectively
// for widgets with a build context that has directionality ltr.
// For rtl, "start" and "end" will be right and left respectively.
@@ -96,7 +97,7 @@ class DatumLegendOptions extends StatelessWidget {
// rows before adding a new column.
desiredMaxRows: 2,
// This defines the padding around each legend entry.
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
cellPadding: const EdgeInsets.only(right: 4.0, bottom: 4.0),
// Render the legend entry text with custom styles.
entryTextStyle: charts.TextStyleSpec(
color: charts.MaterialPalette.purple.shadeDefault,
@@ -110,14 +111,14 @@ class DatumLegendOptions extends StatelessWidget {
/// Create series list with one series
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,