import
'package:flutter/material.dart'
;
import
'package:syncfusion_flutter_charts/charts.dart'
;
void
main() {
return
runApp(_ChartApp());
}
class
_ChartApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'Charts in Flutter'
,
theme: ThemeData(primarySwatch: Colors.blue),
home: _MyHomePage(),
);
}
}
class
_MyHomePage extends StatefulWidget {
_MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class
_MyHomePageState extends State<_MyHomePage> {
@override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(
title:
const
Text(
'GeeksForGeeks'
),
backgroundColor: Colors.green,
),
body: SfCartesianChart(
primaryXAxis: CategoryAxis(),
title: ChartTitle(text:
'Monthly Covid-19 Infections'
),
legend: Legend(isVisible:
true
),
tooltipBehavior: TooltipBehavior(enable:
true
),
series: <ChartSeries<_Infections, String>>[
LineSeries<_Infections, String>(
dataSource: <_Infections>[
_Infections(
'Jan'
, 35000),
_Infections(
'Feb'
, 28000),
_Infections(
'Mar'
, 34000),
_Infections(
'Apr'
, 32000),
_Infections(
'May'
, 40000),
_Infections(
'Jun'
, 60000)
],
xValueMapper: (_Infections victims, _) => victims.year,
yValueMapper: (_Infections victims, _) => victims.victims,
dataLabelSettings: DataLabelSettings(isVisible:
true
))
]));
}
}
class
_Infections {
_Infections(
this
.year,
this
.victims);
final String year;
final
double
victims;
}