You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
import 'package:flutter/material.dart';
|
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
|
import 'package:syncfusion_flutter_core/core.dart';
|
|
|
|
void main() {
|
|
// Register your license here
|
|
SyncfusionLicense.registerLicense(null);
|
|
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> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Syncfusion Flutter chart'),
|
|
),
|
|
body: SfCartesianChart(
|
|
primaryXAxis: CategoryAxis(),
|
|
// Chart title
|
|
title: ChartTitle(text: 'Half yearly sales analysis'),
|
|
// Enable legend
|
|
legend: Legend(isVisible: true),
|
|
// Enable tooltip
|
|
tooltipBehavior: TooltipBehavior(enable: true),
|
|
series: <ChartSeries<SalesData, String>>[
|
|
LineSeries<SalesData, String>(
|
|
dataSource: <SalesData>[
|
|
SalesData('Jan', 35),
|
|
SalesData('Feb', 28),
|
|
SalesData('Mar', 34),
|
|
SalesData('Apr', 32),
|
|
SalesData('May', 40)
|
|
],
|
|
xValueMapper: (SalesData sales, _) => sales.year,
|
|
yValueMapper: (SalesData sales, _) => sales.sales,
|
|
// Enable data label
|
|
dataLabelSettings: DataLabelSettings(isVisible: true)
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
class SalesData {
|
|
SalesData(this.year, this.sales);
|
|
|
|
final String year;
|
|
final double sales;
|
|
}
|