23.3 C
New York
Wednesday, August 17, 2022

How to create Circle Charts (Pie Charts) in Flutter

- Advertisement -

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';

Examples

Example 1: Simple Pie Chart

PieChart(PieChartData(
            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)
           ]
     )
),

Output:

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.

PieChart(PieChartData(
            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)
            ]
      )
),

Output:

Conclusion

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:

Advertisements

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

- Advertisement -

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles