• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter Pie chart with animation

Pie Chart Cirrus CI - Base Branch Build Status GitHub stars Twitter Follow GitHub last commit Website shields.ioOpen Source Love Discord

This Flutter package provides a Pie Chart Widget with cool animation.

More discussions on Discord: https://discord.gg/7byeCn7MGF

πŸ’» Try LIVE Demo

Live Demo: https://apgapg.github.io/pie_chart/

piechart

πŸ’» Installation

In the dependencies: section of your pubspec.yaml, add the following line:

Version

dependencies:
  pie_chart: <latest version>

❔ Usage

Import this class

import 'package:pie_chart/pie_chart.dart';

Usage is simple. Pie Chart is a widget and it just need a Map<String,double> as its data input.

PieChart

Map<String, double> dataMap = {
    "Flutter": 5,
    "React": 3,
    "Xamarin": 2,
    "Ionic": 2,
  };

- Simple Implementation

PieChart(dataMap: dataMap) 

- Full Implementation

PieChart(
      dataMap: dataMap,
      animationDuration: Duration(milliseconds: 800),
      chartLegendSpacing: 32,
      chartRadius: MediaQuery.of(context).size.width / 3.2,
      colorList: colorList,
      initialAngleInDegree: 0,
      chartType: ChartType.ring,
      ringStrokeWidth: 32,
      centerText: "HYBRID",
      legendOptions: LegendOptions(
        showLegendsInRow: false,
        legendPosition: LegendPosition.right,
        showLegends: true,
        legendShape: _BoxShape.circle,
        legendTextStyle: TextStyle(
          fontWeight: FontWeight.bold,
        ),
      ),
      chartValuesOptions: ChartValuesOptions(
        showChartValueBackground: true,
        showChartValues: true,
        showChartValuesInPercentage: false,
        showChartValuesOutside: false,
        decimalPlaces: 1,
      ),
      // gradientList: ---To add gradient colors---
      // emptyColorGradient: ---Empty Color gradient---
    )

Control decimal places 'decimalPlaces'

chartValuesOptions: ChartValuesOptions(
  decimalPlaces: 1,
),

Change legend position with 'legendPosition'

PieChart PieChart PieChart PieChart

Change Chart shape to ring

chartType: ChartType.ring,

PieChart

chartType: ChartType.ring,
showChartValuesOutside: true,

PieChart

Gradient Colors

Pie Chart supports gradient as colors. Just pass gradientList instead of colorList to add gradient to chart colors.

final gradientList = <List<Color>>[
  [
    Color.fromRGBO(223, 250, 92, 1),
    Color.fromRGBO(129, 250, 112, 1),
  ],
  [
    Color.fromRGBO(129, 182, 205, 1),
    Color.fromRGBO(91, 253, 199, 1),
  ],
  [
    Color.fromRGBO(175, 63, 62, 1.0),
    Color.fromRGBO(254, 154, 92, 1),
  ]
];

// Pass gradient to PieChart
gradientList: gradientList,
emptyColorGradient: [
 Color(0xff6c5ce7),
 Colors.blue,
],

PieChart

Base Chart Color

Add a base pie-chart color via:

baseChartColor: Colors.grey

Full code:

class HomePage2 extends StatelessWidget {
  HomePage2({Key? key}) : super(key: key);

  final dataMap = <String, double>{
    "Flutter": 5,
  };

  final colorList = <Color>[
    Colors.greenAccent,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Pie Chart 1"),
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: PieChart(
          dataMap: dataMap,
          chartType: ChartType.ring,
          baseChartColor: Colors.grey[300]!,
          colorList: colorList,
        ),
      ),
    );
  }
}

Total Value

To show chart arcs based on your total value, add totalValue option.

class HomePage2 extends StatelessWidget {
  HomePage2({Key? key}) : super(key: key);

  final dataMap = <String, double>{
    "Flutter": 5,
  };

  final colorList = <Color>[
    Colors.greenAccent,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Pie Chart 1"),
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: PieChart(
          dataMap: dataMap,
          chartType: ChartType.ring,
          baseChartColor: Colors.grey[50]!.withOpacity(0.15),
          colorList: colorList,
          chartValuesOptions: ChartValuesOptions(
            showChartValuesInPercentage: true,
          ),
          totalValue: 20,
        ),
      ),
    );
  }
}

PieChart

⭐ My Flutter Packages

  • json_table GitHub stars Create Flutter Json Table from json map directly.
  • avatar_glow GitHub stars Flutter Avatar Glow Widget with glowing animation.
  • search_widget GitHub stars Flutter Search Widget for selecting an option from list.
  • animating_location_pin GitHub stars Flutter Animating Location Pin Widget providing Animating Location Pin Widget which can be used while fetching device location.

⭐ My Flutter Apps

πŸ‘ Contribution

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

More Repositories

1

avatar_glow

A Flutter Package providing Avatar Glow Widget
C++
260
star
2

json_table

Flutter package: Json Table Widget to create table from json array
Dart
205
star
3

search_widget

Flutter package: Search Widget for selecting an option from a data list.
Dart
196
star
4

flutter_profile

Portfolio made using Flutter
Dart
120
star
5

flutter_physics_concepts

Physics Concepts by Ayush P Gupta
Dart
66
star
6

flutter_responsive_tabs

Flutter Responsive Tabs Demo
Dart
44
star
7

DotMyStyle_App

Official Flutter App of DotMyStyle
Dart
18
star
8

flutter_scrap

Website Scraping with Dart (Flutter)
CMake
17
star
9

vue_bootstrap_5_sample

Bootstrap 5 with VueJs
Vue
15
star
10

animating_location_pin

Animating Location Pin Flutter Package
Dart
15
star
11

flutter_portfolio

Flutter Portfolio of Ayush P Gupta
Dart
15
star
12

flutter_sample_key

Medium Article
Dart
10
star
13

rx_dart_samples

Collection of Rx Dart samples
Dart
10
star
14

flutter_teaching_notes

Questions, answers, notes app for IIT JEE preparation
Dart
9
star
15

flutter_streams

Dart
8
star
16

ShineEffect

Java
7
star
17

flutter_mvp_app

Dart
7
star
18

flutter_sankalan

Dart
7
star
19

flutter_add_bg

Flutter app to write text on images
Java
4
star
20

pixstory-android

Java
4
star
21

vuetify-admin-dashboard

Vue Admin Dashboard Template
Vue
4
star
22

flutter_drop_down

Dart
3
star
23

ReweyouForums

Java
3
star
24

my_hindi_shayari

A sample shayari website built using Svelte and Tailwindcss
Svelte
3
star
25

gravit-design

Gravit Designer illustrations by Ayush P Gupta
3
star
26

apgapg

Hi i am Ayush P Gupta @apgapg
3
star
27

ElasticScrollView

Java
3
star
28

firebase-samples

Different Firebase SDKs samples
JavaScript
2
star
29

flutter_listview_in_scrollview

Dart
2
star
30

flutter_red_screen_error

Dart
2
star
31

DotMyStyle_backend

JavaScript
2
star
32

vue-portfolio

Official portfolio of Ayush P Gupta
Vue
2
star
33

sunserg_web

Sunserg Official frontend web project
Vue
2
star
34

flutter_conference

Dart
2
star
35

git-introduction-001

PPT built using sli.dev
Vue
2
star
36

dotservices_App

Flutter App code of DOT Services
Dart
2
star
37

apgapg.github.io

Portfolio of Ayush P Gupta
HTML
2
star
38

vue3-tailwind-app

Sample demo of Vue3 and Tailwindcss
Vue
2
star
39

nestjs-typescript-sample

Test project for Nestjs
TypeScript
1
star
40

flutter_text_theme_demo

Demo of TextTheme in Flutter
CMake
1
star
41

flutter_flick

Dart
1
star
42

sankalan_web

Sankalan: Self Composed Hindi Poems, Stories
Vue
1
star
43

flutter_git

Dart
1
star
44

flutter_widget_rebuilding

Dart
1
star
45

QA

Java
1
star
46

nuxt-tailwind-app

Nuxt sample with tailwind and daisyui
Vue
1
star
47

flutter_json_parsing

Dart
1
star
48

iitjee

IIT JEE Notes by Ayush P Gupta
Vue
1
star
49

express-routing-controllers-demo

Express Routing Controller npm demo
TypeScript
1
star
50

youtube-vuejs-series

Official Youtube PPT stuffs by TheDotLabs
Vue
1
star
51

awesome-ayushpgupta

Collection of all the awesome repo(s) made with ❀️ by Ayush P Gupta
1
star
52

vuepress_iitjeenotes

Website to showcase IIT JEE notes by Ayush P Gupta
HTML
1
star
53

vuepress-diary

Official Diary of Ayush P Gupta
1
star
54

k8s_ingress_sample

Kubernetes ingress sample
1
star