-
Notifications
You must be signed in to change notification settings - Fork 0
/
historyChart.dart
52 lines (44 loc) · 1.45 KB
/
historyChart.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import "package:flutter/material.dart";
import "package:charts_flutter/flutter.dart" as charts;
class TimeSeriesBar extends StatelessWidget {
final List<charts.Series<TimeSeriesProgress, DateTime>> seriesList;
final bool animate;
TimeSeriesBar._(this.seriesList, {this.animate});
factory TimeSeriesBar(List<Map<String, dynamic>> data) {
return new TimeSeriesBar._(
_createData(data),
animate: true,
);
}
@override
Widget build(BuildContext context) {
return new charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
defaultInteractions: false,
behaviors: [new charts.SelectNearest(), new charts.DomainHighlighter()],
);
}
static List<charts.Series<TimeSeriesProgress, DateTime>> _createData(
List<Map<String, dynamic>> input) {
final data = input
.map((element) =>
TimeSeriesProgress(element["date"], element["progress"]))
.toList();
return [
new charts.Series<TimeSeriesProgress, DateTime>(
id: 'Progress',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesProgress progress, _) => progress.time,
measureFn: (TimeSeriesProgress progress, _) => progress.percent,
data: data,
)
];
}
}
class TimeSeriesProgress {
final DateTime time;
final int percent;
TimeSeriesProgress(this.time, this.percent);
}