BarChart constructor
- Key? key,
- double maxValue = 100,
- double minValue = 0,
- BGDefaultConfig defaultConfig = const BGDefaultConfig(),
- int? totalGroups,
- int? totalBarsPerGroup,
- List<
Group> ? groups, - double interGroupSpace = 10,
- double axisBarSpace = 5,
- AxisLabelFn? axisLabel,
- PopUpFn? defaultPopUp,
- int axisTotalMiddleLabels = 0,
- Bar? emptyBar,
- Group? emptyGroup,
- int? maxBarsInGroup,
- int? maxGroups,
- bool showMinOnAxis = true,
- bool showMaxOnAxis = true,
- Direction direction = Direction.right,
- bool popUpCanOverflow = false,
- bool expandableBarThickness = false,
Creates Animated Horizontal Bar Chart.
If groups
is null, then the value of totalGroups
and
totalBarsPerGroup
is used for generating random values for the graph.
If groups
is null, then, totalGroups
and totalBarsPerGroup
cannot be
null.
axisLabel
can be used to define how to generate a widget to be displayed
according to the corresponding value on the axis.
emptyBar
is used to define the default Bar, which will be displayed
before animating to the actual bar. Recommended: Not to Change.
emptyGroup
is used to define the default Group, which will be displayed
before animating to the actual group. Recommended: Not to Change.
maxBarsInGroup
defines the maximum possible bars a group can have. If
null then the value will be calculated as the max bars in a group. This
value is useful if want smooth animations for bars incoming and outgoing.
maxGroups
defines the maximum possible groups can be. If null then the
value will be calculated as the length of the groups
or totalGroups
accordingly. This value is useful if want smooth animations for groups
which might have initially no bars or emptyBar
s, but can change with
time.
if expandableBarThickness
is set to true, then BarConfig.width will
be ignored.
Note:- If maxBarsInGroup
or maxGroups
is constant for the life-time of
the BarChart, then it is highly recommended to enter these
values, instead of letting it be null.
Important:- This Widget should be built inside a constrained width.
Implementation
BarChart({
super.key,
this.maxValue = 100,
this.minValue = 0,
this.defaultConfig = const BGDefaultConfig(),
int? totalGroups,
int? totalBarsPerGroup,
List<Group>? groups,
this.interGroupSpace = 10,
this.axisBarSpace = 5,
AxisLabelFn? axisLabel,
PopUpFn? defaultPopUp,
this.axisTotalMiddleLabels = 0,
Bar? emptyBar,
Group? emptyGroup,
int? maxBarsInGroup,
int? maxGroups,
this.showMinOnAxis = true,
this.showMaxOnAxis = true,
this.direction = Direction.right,
this.popUpCanOverflow = false,
this.expandableBarThickness = false,
}) : assert(
groups != null ||
(totalGroups != null && totalBarsPerGroup != null),
'If [groups] is null, then, [totalGroups] and [totalBarsPerGroup] cannot be null.'),
assert(axisTotalMiddleLabels >= 0, 'Cannot be negative.'),
axisLabel = axisLabel ?? ((value) => Text('${value.truncate()}')),
emptyBar = FBar(
minValue - 1,
defaultConfig.bar.copyWith(
const BarConfig(color: Colors.transparent),
),
),
emptyGroup = FGroup(bars: [], config: defaultConfig.group) {
this.groups = groups ?? _genGroups(totalGroups!, totalBarsPerGroup!);
this.maxBarsInGroup = maxBarsInGroup ?? _maxBarsInGroup;
this.maxGroups = maxGroups ?? this.groups.length;
}