flutter circular chart
a library for creating animated circular chart widgets with flutter, inspired by zero to one with flutter.
create easily animated pie charts, circular chart and radial charts by providing them with data objects they can plot into charts and animate between.
check the examples folder for the source code for the above screenshots.
installation
install the latest version from pub.
getting started
import the package:
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
create a globalkey to be able to access the chart and update its data:
final globalkey<animatedcircularchartstate> _chartkey = new globalkey<animatedcircularchartstate>();
create chart data entry objects:
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',
),
];
create an animatedcircularchart
, passing it the _chartkey
and initial data
:
@override
widget build(buildcontext context) {
return new animatedcircularchart(
key: _chartkey,
size: const size(300.0, 300.0),
initialchartdata: data,
charttype: circularcharttype.pie,
);
}
call updatedata
to animate the chart:
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);
});
}
customization
hole label:
property | default |
---|---|
holelabel | null |
labelstyle | theme.of(context).texttheme.body2 |
example:
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,
fontsize: 24.0,
),
)
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:
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,
)
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.
Comments are closed.