You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:charts_flutter/flutter.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class GaugeChart extends StatelessWidget {
|
|
final List<Series<dynamic, String>> seriesList;
|
|
final bool animate;
|
|
|
|
GaugeChart(this.seriesList, {this.animate = false});
|
|
|
|
/// Creates a [PieChart] with sample data and no transition.
|
|
factory GaugeChart.withSampleData() {
|
|
return new GaugeChart(
|
|
_createSampleData(),
|
|
// Disable animations for image tests.
|
|
animate: false,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PieChart<String>(
|
|
seriesList, animate: animate, defaultRenderer: ArcRendererConfig(arcRendererDecorators: [ArcLabelDecorator(labelPosition: ArcLabelPosition.auto)]),
|
|
//ArcRendererConfig(arcWidth: 10),
|
|
);
|
|
//);
|
|
}
|
|
|
|
static List<Series<GaugeSegment, String>> _createSampleData() {
|
|
final data = [
|
|
GaugeSegment('Low', 75, MaterialPalette.blue.shadeDefault),
|
|
GaugeSegment('Acceptable', 100, MaterialPalette.blue.shadeDefault),
|
|
GaugeSegment('High', 50, MaterialPalette.blue.shadeDefault),
|
|
GaugeSegment('Highly Unusual', 55, MaterialPalette.blue.shadeDefault),
|
|
];
|
|
|
|
return [
|
|
Series<GaugeSegment, String>(
|
|
id: 'Segments',
|
|
domainFn: (GaugeSegment segment, _) => segment.segment,
|
|
measureFn: (GaugeSegment segment, _) => segment.size,
|
|
data: data,
|
|
)
|
|
];
|
|
}
|
|
}
|
|
|
|
/// Sample data type.
|
|
class GaugeSegment {
|
|
final String segment;
|
|
final int size;
|
|
final color;
|
|
|
|
GaugeSegment(this.segment, this.size, this.color);
|
|
}
|