-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmain_run_doc_example.dart
137 lines (126 loc) · 3.54 KB
/
main_run_doc_example.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import 'package:flutter/material.dart';
import 'package:flutter_charts/flutter_charts.dart';
/// Example app for flutter_charts.
///
/// Intended as a simple app that runs example code from README.md,
/// by replacing the contents of [chartToRun] functions in README.md.
///
void main() {
runApp(const MyApp());
}
/// Returns a [FlutterChart] instance.
///
/// This code can be replaced with any sample code snippets in README.md.
/// See README.md headings named such as
/// ```md
/// ex10RandomData_lineChart
/// ```
Widget chartToRun() {
LabelLayoutStrategy? xContainerLabelLayoutStrategy;
ChartData chartData;
ChartOptions chartOptions = const ChartOptions();
// Set option which will ask to start Y axis at data minimum.
// Even though startYAxisAtDataMinRequested set to true, will not be granted on bar chart
chartOptions = const ChartOptions(
dataContainerOptions: DataContainerOptions(
startYAxisAtDataMinRequested: true,
),
);
chartData = ChartData(
dataRows: const [
[20.0, 25.0, 30.0, 35.0, 40.0, 20.0],
[35.0, 40.0, 20.0, 25.0, 30.0, 20.0],
],
xUserLabels: const ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
dataRowsLegends: const [
'Off zero 1',
'Off zero 2',
],
chartOptions: chartOptions,
);
var lineChartAnchor = LineChartAnchor(
chartData: chartData,
isStacked: false,
xContainerLabelLayoutStrategy: xContainerLabelLayoutStrategy,
);
var lineChart = LineChart(
painter: LineChartPainter(
lineChartAnchor: lineChartAnchor,
),
);
return lineChart;
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
/// Builds the widget which becomes the root of the application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Charts Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(
title: 'Flutter Charts Demo',
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
_MyHomePageState();
void _chartStateChanger() {
setState(() {});
}
/// Builds the widget that is the home page state.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: _chartStateChanger,
child: null,
),
const Text(
'vvvvvvvv:',
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text('>>>'),
Expanded(
// #### Core chart
child: chartToRun(), // verticalBarChart, lineChart
),
const Text('<<'),
],
),
),
const Text('^^^^^^:'),
ElevatedButton(
onPressed: _chartStateChanger,
child: null,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _chartStateChanger,
tooltip: 'New Random Data',
child: const Icon(Icons.add),
),
);
}
}