Search results

Legend

Legend is used to provide valuable information for interpreting what the tree map is displaying and can be represented in various colors, shapes or other identifiers based on data.

Position and alignment

Legend position is used to place legend in various positions. Based on the legend position, the legend item will be aligned. For example, if the position is top or bottom, the legend items are placed by rows. If the position is left or right, the legend items are placed by columns.

The following options are available to customize the legend position:

  • Top
  • Bottom
  • Left
  • Right
  • Float

The following code example shows the legend position.

razor
position.cs
@using Syncfusion.EJ2;
<div id="container">
    @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").RangeColorValuePath("count").LegendSettings(legend => legend.Visible(true).Position(Syncfusion.EJ2.TreeMap.LegendPosition.Top)).LeafItemSettings(leaf => leaf.LabelPath("fruit")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { fruit: 'Apple', count: 5000 },
            { fruit: 'Mango', count: 3000 },
            { fruit: 'Orange', count: 2300 },
            { fruit: 'Banana', count: 500 },
            { fruit: 'Grape', count: 4300 },
            { fruit: 'Papaya', count: 1200 },
            { fruit: 'Melon', count: 4500 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                from: 500,
                to: 3000,
                color: 'orange'
            },
            {
               from: 3000,
               to: 5000,
               color: 'green'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Legend Alignment is used to align the legend items in specific location. The following options are available to customize the legend alignment:

  • Near
  • Center
  • Far

The following code example shows legend alignment.

razor
align.cs
@using Syncfusion.EJ2;
<div id="container">
    @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").RangeColorValuePath("count").LegendSettings(legend => legend.Visible(true).Alignment(Syncfusion.EJ2.TreeMap.Alignment.Far)).LeafItemSettings(leaf => leaf.LabelPath("fruit")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { fruit: 'Apple', count: 5000 },
            { fruit: 'Mango', count: 3000 },
            { fruit: 'Orange', count: 2300 },
            { fruit: 'Banana', count: 500 },
            { fruit: 'Grape', count: 4300 },
            { fruit: 'Papaya', count: 1200 },
            { fruit: 'Melon', count: 4500 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                from: 500,
                to: 3000,
                color: 'orange'
            },
            {
               from: 3000,
               to: 5000,
               color: 'green'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Legend mode

The tree map control supports two different types of legend rendering modes such as Default and Interactive.

Default mode

In default mode, legends have symbols with legend labels that are used to identify the items in tree map control.

The following code example shows the default mode of legends.

razor
default.cs
@using Syncfusion.EJ2;
<div id="container">
            @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").EqualColorValuePath("Brand").LegendSettings(legend => legend.Visible(true).Position(Syncfusion.EJ2.TreeMap.LegendPosition.Top)).LeafItemSettings(leaf => leaf.LabelPath("Car")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { Car: 'Mustang', Brand: 'Ford', count: 232 },
            { Car: 'EcoSport', Brand: 'Ford', count: 121 },
            { Car: 'Swift', Brand: 'Maruti', count: 143 },
            { Car: 'Baleno', Brand: 'Maruti', count: 454 },
            { Car: 'Vitara Brezza', Brand: 'Maruti', count: 545 },
            { Car: 'A3 Cabriolet', Brand: 'Audi', count: 123 },
            { car: 'RS7 Sportback', Brand: 'Audi', count: 523 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                value: 'Ford',
                color: 'green'
            },
            {
                value: 'Audi',
                color: 'red'
            },
            {
                value: 'Maruti',
                color: 'orange'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
        var legend = { color: "black", width: 2 };
        args.treemap.legendSettings.border = legend;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Interactive mode

The legends can be made interactive with an arrow mark that indicates exact range color in legend when the mouse hovers over the corresponding shape. You can enable this option by setting the mode property in legendSettings value to “Interactive”. The default value of the mode property is “Default” to enable normal legend.

The following code example shows the interactive mode of legends.

razor
interactive.cs
@using Syncfusion.EJ2;
<div id="container">
            @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").EqualColorValuePath("Brand").LegendSettings(legend => legend.Visible(true).Mode(Syncfusion.EJ2.TreeMap.LegendMode.Interactive).Position(Syncfusion.EJ2.TreeMap.LegendPosition.Top)).LeafItemSettings(leaf => leaf.LabelPath("Car")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { Car: 'Mustang', Brand: 'Ford', count: 232 },
            { Car: 'EcoSport', Brand: 'Ford', count: 121 },
            { Car: 'Swift', Brand: 'Maruti', count: 143 },
            { Car: 'Baleno', Brand: 'Maruti', count: 454 },
            { Car: 'Vitara Brezza', Brand: 'Maruti', count: 545 },
            { Car: 'A3 Cabriolet', Brand: 'Audi', count: 123 },
            { car: 'RS7 Sportback', Brand: 'Audi', count: 523 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                value: 'Ford',
                color: 'green'
            },
            {
                value: 'Audi',
                color: 'red'
            },
            {
                value: 'Maruti',
                color: 'orange'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
        var legend = { color: "black", width: 2 };
        args.treemap.legendSettings.border = legend;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Legend size

You can customize the legend size by modifying the [height] and [width] properties in the legendSettings. It accepts values in both percentage and pixel. If the value is specified in percentage for height or width, the legend height will be calculated for overall height.

Legend size is shown in the following example.

razor
size.cs
@using Syncfusion.EJ2;
<div id="container">
            @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").EqualColorValuePath("Brand").LegendSettings(legend => legend.Visible(true).Height("50px").Width("200px").Position(Syncfusion.EJ2.TreeMap.LegendPosition.Top)).LeafItemSettings(leaf => leaf.LabelPath("Car")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { Car:'Mustang', Brand:'Ford', count:232 },
            { Car:'EcoSport', Brand:'Ford', count:121 },
            { Car:'Swift', Brand:'Maruti', count:143 },
            { Car:'Baleno', Brand:'Maruti', count:454 },
            { Car:'Vitara Brezza', Brand:'Maruti', count:545 },
            { Car:'A3 Cabriolet', Brand:'Audi',count:123 },
            { car:'RS7 Sportback', Brand:'Audi', count:523 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                value: 'Ford',
                color: 'green'
            },
            {
                value: 'Audi',
                color: 'red'
            },
            {
                value: 'Maruti',
                color: 'orange'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
        var legend = { color: "black", width: 2 };
        args.treemap.legendSettings.border = legend;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Paging support

The tree map supports the legend paging. Legend paging will be enabled if the legend items cannot placed within provided height and width.

The following code example shows enabling legend paging.

razor
paging.cs
@using Syncfusion.EJ2;
<div id="container">
            @Html.EJS().TreeMap("container").Load("load").WeightValuePath("count").EqualColorValuePath("Brand").LegendSettings(legend => legend.Visible(true).Height("50px").Width("100px")).LeafItemSettings(leaf => leaf.LabelPath("Car")).Render()
</div>
<script>
    function load(args)
    { 
        var data = [
            { Car:'Mustang', Brand:'Ford', count:232 },
            { Car:'EcoSport', Brand:'Ford', count:121 },
            { Car:'Swift', Brand:'Maruti', count:143 },
            { Car:'Baleno', Brand:'Maruti', count:454 },
            { Car:'Vitara Brezza', Brand:'Maruti', count:545 },
            { Car:'A3 Cabriolet', Brand:'Audi',count:123 },
            { car:'RS7 Sportback', Brand:'Audi', count:523 }
        ];
        args.treemap.dataSource = data;
        var color = [
            {
                value: 'Ford',
                color: 'green'
            },
            {
                value: 'Audi',
                color: 'red'
            },
            {
                value: 'Maruti',
                color: 'orange'
            }
        ];
        args.treemap.leafItemSettings.colorMapping = color;
        var legend = { color: "black", width: 2 };
        args.treemap.legendSettings.border = legend;
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}