2018-03-21 02:19:47 +00:00
[![pub package ](https://img.shields.io/pub/v/flutter_circular_chart.svg )](https://pub.dartlang.org/packages/flutter_circular_chart)
2017-11-03 03:06:42 +00:00
# Flutter Circular Chart
2017-11-02 23:48:58 +00:00
2017-11-03 03:06:42 +00:00
A library for creating animated circular chart widgets with Flutter, inspired by [Zero to One with Flutter ](https://medium.com/dartlang/zero-to-one-with-flutter-43b13fd7b354 ).
2017-11-03 03:23:07 +00:00
## Overview
Create easily animated pie charts and radial charts by providing them with data objects they can plot into charts and animate between.
2018-05-09 20:31:53 +00:00
![animated_random_radial_chart ](screenshots/animated_random_radial_chart_example.gif )
2017-11-03 03:23:07 +00:00
![animated pie chart ](screenshots/animated_pie_chart_example.gif )
2018-03-21 02:22:45 +00:00
![animated radial chart ](screenshots/animated_radial_chart_example_label.gif )
2017-11-03 03:23:07 +00:00
Check the examples folder for the source code for the above screenshots.
2017-11-03 03:31:49 +00:00
## Contents:
- [Installation ](#installation )
- [Getting Started ](#getting-started )
2018-05-09 20:31:53 +00:00
- [Customization ](#customization )
2017-11-03 03:31:49 +00:00
- [Details ](#details )
- [Chart data entries ](#chart-data-entries )
2017-11-03 03:06:42 +00:00
## Installation
2018-03-21 02:19:47 +00:00
Install the latest version [from pub ](https://pub.dartlang.org/packages/flutter_circular_chart#-installing-tab- ).
2017-11-02 23:48:58 +00:00
## Getting Started
2017-11-03 03:06:42 +00:00
Import the package:
2018-02-22 20:09:28 +00:00
```dart
2017-11-03 03:06:42 +00:00
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
```
2018-02-01 15:41:30 +00:00
Create a [GlobalKey ](https://docs.flutter.io/flutter/widgets/GlobalKey-class.html ) to be able to access the chart and update its data:
2017-11-03 03:06:42 +00:00
2018-02-22 20:09:28 +00:00
```dart
final GlobalKey< AnimatedCircularChartState > _chartKey = new GlobalKey< AnimatedCircularChartState > ();
2018-02-01 15:41:30 +00:00
```
Create chart data entry objects:
2018-01-27 06:46:05 +00:00
2018-02-22 20:09:28 +00:00
```dart
2017-11-03 03:06:42 +00:00
List< CircularStackEntry > data = < CircularStackEntry > [
new CircularStackEntry(
< CircularSegmentEntry > [
new CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
];
```
2018-02-01 15:41:30 +00:00
Create an `AnimatedCircularChart` , passing it the `_chartKey` and initial `data` :
2017-11-03 03:06:42 +00:00
2018-02-22 20:09:28 +00:00
```dart
2017-11-03 03:06:42 +00:00
@override
Widget build(BuildContext context) {
return new AnimatedCircularChart(
key: _chartKey,
2018-01-27 06:46:05 +00:00
size: const Size(300.0, 300.0),
2017-11-03 03:06:42 +00:00
initialChartData: data,
chartType: CircularChartType.Pie,
);
}
```
Call `updateData` to animate the chart:
2018-02-22 20:09:28 +00:00
```dart
2017-11-03 03:06:42 +00:00
void _cycleSamples() {
List< CircularStackEntry > nextData = < CircularStackEntry > [
new CircularStackEntry(
< CircularSegmentEntry > [
new CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
];
setState(() {
_chartKey.currentState.updateData(nextData);
});
}
```
2018-05-09 20:31:53 +00:00
## Customization
### Hole Label:
| Property | Default |
|------------|:---------------------------------:|
| holeLabel | null |
| labelStyle | Theme.of(context).textTheme.body2 |
Example:
```dart
new AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: < CircularStackEntry > [
new CircularStackEntry(
< CircularSegmentEntry > [
new CircularSegmentEntry(
33.33,
Colors.blue[400],
rankKey: 'completed',
),
new CircularSegmentEntry(
66.67,
Colors.blueGrey[600],
rankKey: 'remaining',
),
],
rankKey: 'progress',
),
],
chartType: CircularChartType.Radial,
percentageValues: true,
holeLabel: '1/3',
labelStyle: new TextStyle(
color: Colors.blueGrey[600],
fontWeight: FontWeight.bold,
2018-05-09 20:45:27 +00:00
fontSize: 24.0,
2018-05-09 20:31:53 +00:00
),
)
```
![hole label example screenshot ](screenshots/hole_label_example.png )
---
### Segment Edge Style:
| Property | Default |
|------------|:---------------------:|
| edgeStyle | SegmentEdgeStyle.flat |
| SegmentEdgeStyle | Description |
|:----------------:|--------------------------------------------|
| flat (default) | Segments begin and end with a flat edge. |
| round | Segments begin and end with a semi-circle. |
Example:
```dart
new AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: < CircularStackEntry > [
new CircularStackEntry(
< CircularSegmentEntry > [
new CircularSegmentEntry(
33.33,
Colors.blue[400],
rankKey: 'completed',
),
new CircularSegmentEntry(
66.67,
Colors.blueGrey[600],
rankKey: 'remaining',
),
],
rankKey: 'progress',
),
],
chartType: CircularChartType.Radial,
edgeStyle: SegmentEdgeStyle.round,
percentageValues: true,
)
```
![round segment edge example screenshot ](screenshots/segment_edge_round_example.png )
2017-11-03 03:31:49 +00:00
## Details
### Chart data entries:
Charts expect a list of `CircularStackEntry` objects containing the data they need to be drawn.
Each `CircularStackEntry` corresponds to a complete circle in the chart. For radial charts that is one of the rings, for pie charts it is the whole pie.
Radial charts with multiple `CircularStackEntry` s will display them as concentric circles.
Each `CircularStackEntry` is composed of multiple `CircularSegmentEntry` s containing the value of a data point. In radial charts a segment corresponds to an arc segment of the current ring, for pie charts it is an individual slice.
2017-11-02 23:48:58 +00:00