0.5 C
New York
Tuesday, November 28, 2023

How to create Circle Charts (Pie Charts) in Flutter

Charts are a visual tool to represent data, making it easier for users to grasp information than dry numbers. There’re several plugins that can help us easily make circle charts (pie charts) in Flutter. In this tutorial, we’ll use fl_chart, one of the most popular chart plugins on pub.dev.

Installing the plugin

1. Add the package name to the dependencies section in your pubspec.yaml by executing this:Advertisements

flutter pub add fl_chart

2. Run the following command :

flutter pub get

3. Import the plugin into your project:

import 'package:fl_chart/fl_chart.dart';


Example 1: Simple Pie Chart

            centerSpaceRadius: 10,
            borderData: FlBorderData(show: false),
            sections: [
              PieChartSectionData(value: 10, color: Colors.purple, radius: 100),
              PieChartSectionData(value: 20, color: Colors.amber, radius: 110),
              PieChartSectionData(value: 30, color: Colors.green, radius: 120)


Example 2: Doughnut Chart

AdvertisementsThis example creates a doughnut chart. This name can make you get confused but it is simply a pie chart with a big hole in the middle.

            centerSpaceRadius: 100,
            centerSpaceColor: Colors.yellow,
            borderData: FlBorderData(show: false),
            sections: [
              PieChartSectionData(value: 10, color: Colors.blue),
              PieChartSectionData(value: 10, color: Colors.orange),
              PieChartSectionData(value: 10, color: Colors.red),
              PieChartSectionData(value: 10, color: Colors.purple),
              PieChartSectionData(value: 20, color: Colors.amber),
              PieChartSectionData(value: 30, color: Colors.green)



We’ve gone through a few examples of implementing pie charts in mobile applications. If you’d like to learn more new and interesting things in Flutter, take a look at the following articles:


You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Related Articles

Latest Articles