1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +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

@@ -35,11 +35,12 @@ class SegmentsLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
SegmentsLineChart(this.seriesList, {this.animate});
const SegmentsLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory SegmentsLineChart.withSampleData() {
return new SegmentsLineChart(
return SegmentsLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -51,45 +52,45 @@ class SegmentsLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory SegmentsLineChart.withRandomData() {
return new SegmentsLineChart(_createRandomData());
return SegmentsLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
// Series of data with static dash pattern and stroke width. The colorFn
// accessor will colorize each datum (for all three series).
final colorChangeData = [
new LinearSales(0, random.nextInt(100), null, 2.0),
new LinearSales(1, random.nextInt(100), null, 2.0),
new LinearSales(2, random.nextInt(100), null, 2.0),
new LinearSales(3, random.nextInt(100), null, 2.0),
new LinearSales(4, random.nextInt(100), null, 2.0),
new LinearSales(5, random.nextInt(100), null, 2.0),
new LinearSales(6, random.nextInt(100), null, 2.0),
LinearSales(0, random.nextInt(100), null, 2.0),
LinearSales(1, random.nextInt(100), null, 2.0),
LinearSales(2, random.nextInt(100), null, 2.0),
LinearSales(3, random.nextInt(100), null, 2.0),
LinearSales(4, random.nextInt(100), null, 2.0),
LinearSales(5, random.nextInt(100), null, 2.0),
LinearSales(6, random.nextInt(100), null, 2.0),
];
// Series of data with changing color and dash pattern.
final dashPatternChangeData = [
new LinearSales(0, random.nextInt(100), [2, 2], 2.0),
new LinearSales(1, random.nextInt(100), [2, 2], 2.0),
new LinearSales(2, random.nextInt(100), [4, 4], 2.0),
new LinearSales(3, random.nextInt(100), [4, 4], 2.0),
new LinearSales(4, random.nextInt(100), [4, 4], 2.0),
new LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0),
new LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0),
LinearSales(0, random.nextInt(100), [2, 2], 2.0),
LinearSales(1, random.nextInt(100), [2, 2], 2.0),
LinearSales(2, random.nextInt(100), [4, 4], 2.0),
LinearSales(3, random.nextInt(100), [4, 4], 2.0),
LinearSales(4, random.nextInt(100), [4, 4], 2.0),
LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0),
LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0),
];
// Series of data with changing color and stroke width.
final strokeWidthChangeData = [
new LinearSales(0, random.nextInt(100), null, 2.0),
new LinearSales(1, random.nextInt(100), null, 2.0),
new LinearSales(2, random.nextInt(100), null, 4.0),
new LinearSales(3, random.nextInt(100), null, 4.0),
new LinearSales(4, random.nextInt(100), null, 4.0),
new LinearSales(5, random.nextInt(100), null, 6.0),
new LinearSales(6, random.nextInt(100), null, 6.0),
LinearSales(0, random.nextInt(100), null, 2.0),
LinearSales(1, random.nextInt(100), null, 2.0),
LinearSales(2, random.nextInt(100), null, 4.0),
LinearSales(3, random.nextInt(100), null, 4.0),
LinearSales(4, random.nextInt(100), null, 4.0),
LinearSales(5, random.nextInt(100), null, 6.0),
LinearSales(6, random.nextInt(100), null, 6.0),
];
// Generate 2 shades of each color so that we can style the line segments.
@@ -98,7 +99,7 @@ class SegmentsLineChart extends StatelessWidget {
final green = charts.MaterialPalette.green.makeShades(2);
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Color Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -109,7 +110,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: colorChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Dash Pattern Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -120,7 +121,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: dashPatternChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Stroke Width Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -137,9 +138,9 @@ class SegmentsLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
defaultRenderer:
new charts.LineRendererConfig(includeArea: true, stacked: true),
charts.LineRendererConfig(includeArea: true, stacked: true),
animate: animate);
}
@@ -148,35 +149,35 @@ class SegmentsLineChart extends StatelessWidget {
// Series of data with static dash pattern and stroke width. The colorFn
// accessor will colorize each datum (for all three series).
final colorChangeData = [
new LinearSales(0, 5, null, 2.0),
new LinearSales(1, 15, null, 2.0),
new LinearSales(2, 25, null, 2.0),
new LinearSales(3, 75, null, 2.0),
new LinearSales(4, 100, null, 2.0),
new LinearSales(5, 90, null, 2.0),
new LinearSales(6, 75, null, 2.0),
LinearSales(0, 5, null, 2.0),
LinearSales(1, 15, null, 2.0),
LinearSales(2, 25, null, 2.0),
LinearSales(3, 75, null, 2.0),
LinearSales(4, 100, null, 2.0),
LinearSales(5, 90, null, 2.0),
LinearSales(6, 75, null, 2.0),
];
// Series of data with changing color and dash pattern.
final dashPatternChangeData = [
new LinearSales(0, 5, [2, 2], 2.0),
new LinearSales(1, 15, [2, 2], 2.0),
new LinearSales(2, 25, [4, 4], 2.0),
new LinearSales(3, 75, [4, 4], 2.0),
new LinearSales(4, 100, [4, 4], 2.0),
new LinearSales(5, 90, [8, 3, 2, 3], 2.0),
new LinearSales(6, 75, [8, 3, 2, 3], 2.0),
LinearSales(0, 5, [2, 2], 2.0),
LinearSales(1, 15, [2, 2], 2.0),
LinearSales(2, 25, [4, 4], 2.0),
LinearSales(3, 75, [4, 4], 2.0),
LinearSales(4, 100, [4, 4], 2.0),
LinearSales(5, 90, [8, 3, 2, 3], 2.0),
LinearSales(6, 75, [8, 3, 2, 3], 2.0),
];
// Series of data with changing color and stroke width.
final strokeWidthChangeData = [
new LinearSales(0, 5, null, 2.0),
new LinearSales(1, 15, null, 2.0),
new LinearSales(2, 25, null, 4.0),
new LinearSales(3, 75, null, 4.0),
new LinearSales(4, 100, null, 4.0),
new LinearSales(5, 90, null, 6.0),
new LinearSales(6, 75, null, 6.0),
LinearSales(0, 5, null, 2.0),
LinearSales(1, 15, null, 2.0),
LinearSales(2, 25, null, 4.0),
LinearSales(3, 75, null, 4.0),
LinearSales(4, 100, null, 4.0),
LinearSales(5, 90, null, 6.0),
LinearSales(6, 75, null, 6.0),
];
// Generate 2 shades of each color so that we can style the line segments.
@@ -185,7 +186,7 @@ class SegmentsLineChart extends StatelessWidget {
final green = charts.MaterialPalette.green.makeShades(2);
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Color Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -196,7 +197,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: colorChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Dash Pattern Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -207,7 +208,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: dashPatternChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Stroke Width Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>