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

@@ -25,11 +25,11 @@ class GaugeChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
GaugeChart(this.seriesList, {this.animate});
const GaugeChart(this.seriesList, {this.animate, Key key}) : super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory GaugeChart.withSampleData() {
return new GaugeChart(
return GaugeChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,22 +41,22 @@ class GaugeChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory GaugeChart.withRandomData() {
return new GaugeChart(_createRandomData());
return GaugeChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<GaugeSegment, String>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new GaugeSegment('Low', random.nextInt(100)),
new GaugeSegment('Acceptable', random.nextInt(100)),
new GaugeSegment('High', random.nextInt(100)),
new GaugeSegment('Highly Unusual', random.nextInt(100)),
GaugeSegment('Low', random.nextInt(100)),
GaugeSegment('Acceptable', random.nextInt(100)),
GaugeSegment('High', random.nextInt(100)),
GaugeSegment('Highly Unusual', random.nextInt(100)),
];
return [
new charts.Series<GaugeSegment, String>(
charts.Series<GaugeSegment, String>(
id: 'Segments',
domainFn: (GaugeSegment segment, _) => segment.segment,
measureFn: (GaugeSegment segment, _) => segment.size,
@@ -68,26 +68,26 @@ class GaugeChart 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 30px. The remaining space in
// the chart will be left as a hole in the center. Adjust the start
// angle and the arc length of the pie so it resembles a gauge.
defaultRenderer: new charts.ArcRendererConfig(
defaultRenderer: charts.ArcRendererConfig(
arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi));
}
/// Create one series with sample hard coded data.
static List<charts.Series<GaugeSegment, String>> _createSampleData() {
final data = [
new GaugeSegment('Low', 75),
new GaugeSegment('Acceptable', 100),
new GaugeSegment('High', 50),
new GaugeSegment('Highly Unusual', 5),
GaugeSegment('Low', 75),
GaugeSegment('Acceptable', 100),
GaugeSegment('High', 50),
GaugeSegment('Highly Unusual', 5),
];
return [
new charts.Series<GaugeSegment, String>(
charts.Series<GaugeSegment, String>(
id: 'Segments',
domainFn: (GaugeSegment segment, _) => segment.segment,
measureFn: (GaugeSegment segment, _) => segment.size,