-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.dart
101 lines (92 loc) · 3.22 KB
/
main.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
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:intl/intl.dart';
void main() {
return runApp(ChartApp());
}
class ChartApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Chart Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
// ignore: prefer_const_constructors_in_immutables
MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late TooltipBehavior _tooltipBehavior;
@override
void initState() {
_tooltipBehavior = TooltipBehavior(enable: true);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Syncfusion Flutter chart'),
),
body: Center(
child: Container(
height: 500,
width: 320,
child: SfCartesianChart(
backgroundColor: Colors.white,
plotAreaBackgroundColor: Colors.white,
onTooltipRender: (TooltipArgs args) {
if (args.pointIndex == 0) {
//Tooltip without header
args.header = '';
}
if (args.pointIndex == 1) {
//Tooltip with customized header
args.header = 'Sold';
}
if (args.pointIndex == 2) {
//Tooltip with X and Y positions of data points
args.header = 'x : y';
args.text =
'${args.locationX!.floor()} : ${args.locationY!.floor()}';
}
if (args.pointIndex == 3) {
//Tooltip with formatted DateTime values
List<dynamic>? chartdata = args.dataPoints;
args.header =
DateFormat('d MMM yyyy').format(chartdata![3].x);
args.text = '${chartdata[3].y}';
}
},
primaryXAxis: DateTimeAxis(
interval: 30, intervalType: DateTimeIntervalType.days),
// Enable tooltip
tooltipBehavior: _tooltipBehavior,
series: <LineSeries<SalesData, DateTime>>[
LineSeries<SalesData, DateTime>(
enableTooltip: true,
dataSource: <SalesData>[
SalesData(DateTime(2020, 01, 31), 35),
SalesData(DateTime(2020, 02, 28), 28),
SalesData(DateTime(2020, 03, 31), 34),
SalesData(DateTime(2020, 04, 30), 32),
SalesData(DateTime(2020, 05, 31), 40)
],
xValueMapper: (SalesData sales, _) => sales.date,
yValueMapper: (SalesData sales, _) => sales.sales,
)
]),
),
));
}
}
class SalesData {
SalesData(this.date, this.sales);
final DateTime date;
final double sales;
}