labelOverflow property

MapLabelOverflow labelOverflow
final

Trims or removes the legend text when it is overflowed from the bar legend. Defaults to MapLabelOverflow.hide.

By default, the legend labels will render even if it overflows form the bar legend. Using this property, it is possible to remove or trim the legend labels based on the bar legend size.

This snippet shows how to set the overflowMode for the bar legend text in SfMaps.

late List<DataModel> _data;
late MapShapeSource _mapSource;

 @override
 void initState() {
   super.initState();

   _data = <DataModel>[
     DataModel('India', 280, "Low"),
     DataModel('United States of America', 190, "High"),
     DataModel('Pakistan', 37, "Low"),
   ];

   _mapSource = MapShapeSource.asset(
     "assets/world_map.json",
     shapeDataField: "name",
     dataCount: _data.length,
     primaryValueMapper: (int index) {
       return _data[index].country;
     },
     shapeColorValueMapper: (int index) {
       return _data[index].storage;
     },
     shapeColorMappers: [
       MapColorMapper(value: "Low", color: Colors.red),
       MapColorMapper(value: "High", color: Colors.green)
     ],
   );
 }

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
       title: Text('Bar legend'),
     ),
     body: Center(
       child: SfMaps(
         layers: [
           MapShapeLayer(
             source: _mapSource,
             legend: MapLegend.bar(
               MapElement.shape,
               labelOverflow: MapLabelOverflow.hide,
             ),
           )
         ],
       ),
     ),
   );
 }

class DataModel {
  const DataModel(this.country, this.count, this.storage);

  final String country;
  final double count;
  final String storage;
}

See also:

  • labelsPlacement, place the labels either between the segments or on the segments.
  • edgeLabelsPlacement, to place the edge labels either inside or outside of the bar legend.

Implementation

final MapLabelOverflow labelOverflow;