TreemapLegend.bar constructor
- bool shouldAlwaysShowScrollbar = false,
- Widget? title,
- TreemapLegendOverflowMode overflowMode = TreemapLegendOverflowMode.scroll,
- EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0),
- TreemapLegendPosition position = TreemapLegendPosition.top,
- Offset? offset,
- double spacing = 2.0,
- TextStyle? textStyle,
- Axis? direction,
- Size? segmentSize,
- TreemapLegendLabelsPlacement? labelsPlacement,
- TreemapLegendEdgeLabelsPlacement edgeLabelsPlacement = TreemapLegendEdgeLabelsPlacement.inside,
- TreemapLabelOverflow labelOverflow = TreemapLabelOverflow.visible,
- TreemapLegendPaintingStyle segmentPaintingStyle = TreemapLegendPaintingStyle.solid,
- bool showPointerOnHover = false,
- TreemapLegendPointerBuilder? pointerBuilder,
- Color? pointerColor,
- Size pointerSize = const Size(16, 12),
Creates a bar type legend for the tree map.
Information provided in the legend helps to identify the data rendered in the tree map.
Defaults to null
.
By default, legend will not be shown.
-
labelsPlacement - Places the labels either between the bar items or on the items. By default, labels placement will be TreemapLegendLabelsPlacement.betweenItems when setting range color mapping TreemapColorMapper without setting TreemapColorMapper.name property. In all other cases, it will be TreemapLegendLabelsPlacement.onItem.
-
edgeLabelsPlacement - Places the edge labels either inside or at center of the edges. It doesn't work with TreemapLegendLabelsPlacement.betweenItems. Defaults to TreemapLegendEdgeLabelsPlacement.inside.
-
segmentPaintingStyle - Option for setting solid or gradient color for the bar. To enable the gradient, set this as TreemapLegendPaintingStyle.gradient. Defaults to TreemapLegendPaintingStyle.solid.
-
labelOverflow - Option to trim or remove the legend item's text when it is overflowed. Defaults to TreemapLabelOverflow.hide.
late List<SocialMediaUsers> _source;
late List<TreemapColorMapper> _colorMappers;
@override
void initState() {
_source = <SocialMediaUsers>[
SocialMediaUsers('India', 'Facebook', 280),
SocialMediaUsers('India', 'Instagram', 88),
SocialMediaUsers('USA', 'Facebook', 190),
SocialMediaUsers('USA', 'Instagram', 120),
SocialMediaUsers('Japan', 'Twitter', 48),
SocialMediaUsers('Japan', 'Instagram', 31),
];
_colorMappers = <TreemapColorMapper>[
TreemapColorMapper.range(
from: 0, to: 10, color: Colors.red, name: '10'),
TreemapColorMapper.range(
from: 11, to: 20, color: Colors.green, name: '20'),
TreemapColorMapper.range(
from: 21, to: 30, color: Colors.blue, name: '30'),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SfTreemap(
dataCount: _source.length,
weightValueMapper: (int index) {
return _source[index].usersInMillions;
},
levels: [
TreemapLevel(
groupMapper: (int index) {
return _source[index].country;
},
),
],
legend: TreemapLegend(),
colorMappers: _colorMappers,
),
);
}
class SocialMediaUsers {
const SocialMediaUsers(
this.country,
this.socialMedia,
this.usersInMillions,
);
final String country;
final String socialMedia;
final double usersInMillions;
}
See also:
- TreemapLegend, for adding default legend type with different icon styles like circle, diamond, rectangle and triangle.
Implementation
const TreemapLegend.bar({
this.shouldAlwaysShowScrollbar = false,
this.title,
this.overflowMode = TreemapLegendOverflowMode.scroll,
this.padding = const EdgeInsets.all(10.0),
this.position = TreemapLegendPosition.top,
this.offset,
this.spacing = 2.0,
this.textStyle,
this.direction,
this.segmentSize,
this.labelsPlacement,
this.edgeLabelsPlacement = TreemapLegendEdgeLabelsPlacement.inside,
this.labelOverflow = TreemapLabelOverflow.visible,
this.segmentPaintingStyle = TreemapLegendPaintingStyle.solid,
this.showPointerOnHover = false,
this.pointerBuilder,
this.pointerColor,
this.pointerSize = const Size(16, 12),
}) : _type = _LegendType.bar,
iconType = TreemapIconType.circle,
iconSize = const Size(8.0, 8.0),
assert(spacing >= 0);