TreemapLegend class

Shows legend for the data rendered in the treemap.

By default, legend will not be shown.

If SfTreemap.colorMappers is null, then the legend items' icon color and legend item's text will be applied based on the value of TreemapLevel.color and the values returned from the TreemapLevel.groupMapper callback of first TreemapLevel added in the SfTreemap.levels collection.

If SfTreemap.colorMappers is not null and TreemapColorMapper.value constructor is used, the legend item's icon color will be applied based on the TreemapColorMapper.color property and the legend text applied based on the TreemapColorMapper.value property.

And, when using TreemapColorMapper.range constructor, the legend item's icon color will be applied based on the TreemapColorMapper.color property and the legend text will be applied based on the TreemapColorMapper.name property. If the TreemapColorMapper.name property is null, then the text will be applied based on the TreemapColorMapper.from and TreemapColorMapper.to properties

The below code snippet represents how to setting default legend to the tree map.

late List<SocialMediaUsers> _source;

@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),
  ];
  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(),
    ),
  );
}

class SocialMediaUsers {
  const SocialMediaUsers(
    this.country,
    this.socialMedia,
    this.usersInMillions,
  );
  final String country;
  final String socialMedia;
  final double usersInMillions;
}

The below code snippet represents how to setting bar legend to the tree map.

late List<SocialMediaUsers> _source;

@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),
  ];
  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.bar(),
    ),
  );
}

class SocialMediaUsers {
  const SocialMediaUsers(
    this.country,
    this.socialMedia,
    this.usersInMillions,
  );
  final String country;
  final String socialMedia;
  final double usersInMillions;
}

See also:

Inheritance
Annotations

Constructors

TreemapLegend({bool shouldAlwaysShowScrollbar = false, Widget? title, TreemapLegendPosition position = TreemapLegendPosition.top, Offset? offset, TreemapLegendOverflowMode overflowMode = TreemapLegendOverflowMode.wrap, Axis? direction, EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0), double spacing = 10.0, TextStyle? textStyle, TreemapIconType iconType = TreemapIconType.circle, Size iconSize = const Size(8.0, 8.0)})
Provides additional information about the data rendered in the tree map by initializing the SfTreemap.legend property.
const
TreemapLegend.bar({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.
const

Properties

direction Axis?
Arranges the legend items in either horizontal or vertical direction.
final
edgeLabelsPlacement TreemapLegendEdgeLabelsPlacement
Place the edge labels either inside or outside of the bar legend.
final
hashCode int
The hash code for this object.
no setteroverride
iconSize Size
Customizes the size of the icon.
final
iconType TreemapIconType
Specifies the shape of the legend icon.
final
labelOverflow TreemapLabelOverflow
Trims or removes the legend text when it is overflowed from the bar legend.
final
labelsPlacement TreemapLegendLabelsPlacement?
Place the labels either between the segments or on the segments.
final
offset Offset?
Places the legend in custom position.
final
overflowMode TreemapLegendOverflowMode
Wraps or scrolls the legend items when it overflows.
final
padding EdgeInsetsGeometry?
Sets the padding around the legend.
final
pointerBuilder TreemapLegendPointerBuilder?
Returns a widget for the given value.
final
pointerColor Color?
Customizes the color of the pointer.
final
pointerSize Size
Customizes the size of the pointer.
final
position TreemapLegendPosition
Positions the legend in the different directions.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
segmentPaintingStyle TreemapLegendPaintingStyle
Applies gradient or solid color for the bar segments.
final
segmentSize Size?
Customizes the size of the bar segments.
final
shouldAlwaysShowScrollbar bool
Toggles the scrollbar visibility.
final
showPointerOnHover bool
Specifies whether the pointer should be shown while hovering on the TreemapLegend segments.
final
spacing double
Specifies the space between the each legend items.
final
textStyle TextStyle?
Customizes the legend item's text style.
final
title Widget?
Enables a title for the legends to provide a small note about the legends.
final

Methods

debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override