flutter_mini_chart 1.0.0
flutter_mini_chart: ^1.0.0 copied to clipboard
Lightweight, animated, interactive charts for Flutter. Bar, pie, doughnut charts with zero dependencies.
import 'package:flutter/material.dart';
import 'package:flutter_mini_chart/flutter_mini_chart.dart';
void main() => runApp(const ExampleApp());
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_mini_chart Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
useMaterial3: true,
),
home: const ChartDemoPage(),
);
}
}
class ChartDemoPage extends StatelessWidget {
const ChartDemoPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('flutter_mini_chart')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Bar Chart',
style: Theme.of(context).textTheme.headlineSmall),
const SizedBox(height: 12),
SizedBox(
height: 300,
child: MiniBarChart(
data: const [
BarData(label: 'Jan', value: 30),
BarData(label: 'Feb', value: 50),
BarData(label: 'Mar', value: 20),
BarData(label: 'Apr', value: 70),
BarData(label: 'May', value: 45),
BarData(label: 'Jun', value: 60),
],
style: const BarChartStyle(showDataLabels: true),
legend: const ChartLegend(position: LegendPosition.bottom),
onBarTap: (index, data) {
debugPrint('Tapped bar $index: ${data.label} = ${data.value}');
},
),
),
const SizedBox(height: 40),
Text('Pie Chart',
style: Theme.of(context).textTheme.headlineSmall),
const SizedBox(height: 12),
SizedBox(
height: 300,
child: MiniPieChart(
data: const [
PieData(label: 'Error', value: 35),
PieData(label: 'Warning', value: 25),
PieData(label: 'Info', value: 40),
],
legend: const ChartLegend(position: LegendPosition.bottom),
onSliceTap: (index, data) {
debugPrint(
'Tapped slice $index: ${data.label} = ${data.value}');
},
),
),
const SizedBox(height: 40),
Text('Doughnut Chart',
style: Theme.of(context).textTheme.headlineSmall),
const SizedBox(height: 12),
SizedBox(
height: 300,
child: MiniPieChart(
data: const [
PieData(label: 'Online', value: 75),
PieData(label: 'Offline', value: 15),
PieData(label: 'Unknown', value: 10),
],
style: const PieChartStyle(innerRadius: 60),
legend: const ChartLegend(position: LegendPosition.right),
),
),
],
),
),
);
}
}