JavaScript/jQuery TreeMap API

The TreeMap is a widget that displays hierarchical data by using nested rectangles.

import TreeMap from "devextreme/viz/tree_map"

In the TreeMap widget, hierarchical data is represented by a set of nested rectangles whose sizes are proportional to the visualized values. TreeMap operates with plain and hierarchical data sources. Also, it can visualize a hierarchy reconstructed from a flat data source.

TreeMap provides three layout algorithms out-of-the-box along with the capability to implement your own algorithm. In addition, the widget includes API methods that enable you to implement the drill down feature. Moreover, TreeMap supports all interactive features available in other DevExtreme Data Visualization Widgets: click, hover and selection.

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the TreeMap widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
var fruitsVegetables = [{
    name: 'Fruits',
    items: [
        { name: 'Apples', value: 4 },
        { name: 'Oranges', value: 10 },
        { name: 'Lemons', value: 6 }
    ]
}, {
    name: 'Vegetables',
    items: [
        { name: 'Cucumbers', value: 4 },
        { name: 'Tomatoes', value: 8 },
        { name: 'Turnips', value: 7 }
    ]
}];
$(function() {
    $("#treeMap").dxTreeMap({
        dataSource: fruitsVegetables
    });
});
<div id="treeMap"></div>
Angular
HTML
TypeScript
<dx-tree-map [dataSource]="fruitsVegetables"></dx-tree-map>
export class AppComponent {
    fruitsVegetables = [
        // ...   
    ];
}
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-tree-map="{
        dataSource: fruitsVegetables
    }"></div>
</div>
angular.module('DemoApp', ['dx'])
    .controller("DemoController", function ($scope) {
        $scope.fruitsVegetables = [
            // ...   
        ];
    });
Knockout
HTML
JavaScript
<div data-bind="dxTreeMap: {
    dataSource: fruitsVegetables
}"></div>
var viewModel = {
    fruitsVegetables: [
        // ...
    ]
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().TreeMap()
    .ID("treeMap")
    .DataSource(FruitsVegetables)
)
@(Html.DevExtreme().TreeMap() _
    .ID("treeMap") _
    .DataSource(FruitsVegetables)
)

View Demo Watch Video

See Also

Configuration

This section describes properties that configure the contents, behavior and appearance of the TreeMap widget.

Name Description
childrenField

Specifies the name of the data source field that provides nested items for a group. Applies to hierarchical data sources only.

colorField

Specifies the name of the data source field that provides colors for tiles.

colorizer

Manages the color settings.

dataSource

Specifies the origin of data for the widget.

elementAttr

Specifies the attributes to be attached to the widget's root element.

export

Configures the exporting and printing features.

group

Configures groups.

hoverEnabled

Specifies whether tiles and groups change their style when a user pauses on them.

idField

Specifies the name of the data source field that provides IDs for items. Applies to plain data sources only.

interactWithGroup

Specifies whether the user will interact with a single tile or its group.

labelField

Specifies the name of the data source field that provides texts for tile and group labels.

layoutAlgorithm

Specifies the layout algorithm.

layoutDirection

Specifies the direction in which the items will be laid out.

loadingIndicator

Configures the loading indicator.

maxDepth

Specifies how many hierarchical levels must be visualized.

onClick

A handler for the click event.

onDisposing

A handler for the disposing event. Executed when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

onDrawn

A function that is executed when the widget's rendering has finished.

onDrill

A handler for the drill event.

onExported

A handler for the exported event. Executed after data from the widget is exported.

onExporting

A handler for the exporting event. Executed before data from the widget is exported.

onFileSaving

A handler for the fileSaving event. Executed before a file with exported data is saved on the user's local storage.

onHoverChanged

A handler for the hoverChanged event.

onIncidentOccurred

A handler for the incidentOccurred event. Executed when an error or warning appears in the widget.

onInitialized

A handler for the initialized event. Executed only once, after the widget is initialized.

onNodesInitialized

A handler for the nodesInitialized event.

onNodesRendering

A handler for the nodesRendering event.

onOptionChanged

A handler for the optionChanged event. Executed after an option of the widget is changed.

onSelectionChanged

A handler for the selectionChanged event.

parentField

Specifies the name of the data source field that provides parent IDs for items. Applies to plain data sources only.

pathModified

Notifies the widget that it is embedded into an HTML page that uses a tag modifying the path.

redrawOnResize

Specifies whether to redraw the widget when the size of the parent browser window changes or a mobile device rotates.

resolveLabelOverflow

Decides whether those labels that overflow their tile/group should be hidden or truncated with ellipsis.

rtlEnabled

Switches the widget to a right-to-left representation.

selectionMode

Specifies whether a single or multiple nodes can be in the selected state simultaneously.

size

Specifies the widget's size in pixels.

theme

Sets the name of the theme the widget uses.

tile

Configures tiles.

title

Configures the widget's title.

tooltip

Configures tooltips - small pop-up rectangles that display information about a data-visualizing widget element being pressed or hovered over with the mouse pointer.

valueField

Specifies the name of the data source field that provides values for tiles.

Methods

This section describes methods that can be called to manipulate the TreeMap widget.

Name Description
beginUpdate()

Prevents the widget from refreshing until the endUpdate() method is called.

clearSelection()

Deselects all nodes in the widget.

dispose()

Disposes of all the resources allocated to the TreeMap instance.

drillUp()

Drills one level up.

element()

Gets the root widget element.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

exportTo(fileName, format)

Exports the widget.

getCurrentNode()

Gets the current node.

getDataSource()

Gets the DataSource instance.

getInstance(element)

Gets the instance of a widget found using its DOM node.

getRootNode()

Gets the root node.

getSize()

Gets the current widget size.

hideLoadingIndicator()

Hides the loading indicator.

hideTooltip()

Hides the tooltip.

instance()

Gets the widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from a single event.

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

on(eventName, eventHandler)

Subscribes to an event.

on(events)

Subscribes to events.

option()

Gets all widget options.

option(optionName)

Gets the value of a single option.

option(optionName, optionValue)

Updates the value of a single option.

option(options)

Updates the values of several options.

print()

Opens the browser's print window.

render()

Redraws the widget.

resetDrillDown()

Resets the drill down level.

showLoadingIndicator()

Shows the loading indicator.

svg()

Gets the widget's SVG markup.

Events

This section describes events fired by this widget.

Name Description
click

Fires when the user clicks a node.

disposing

Raised when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

drawn

Raised when the widget's rendering has finished.

drill

Fires when the user drills up or down.

exported

Raised after data from the widget is exported.

exporting

Raised before data from the widget is exported.

fileSaving

Raised before a file with exported data is saved on the user's local storage.

hoverChanged

Fires when the hover state of a node has been changed.

incidentOccurred

Raised when an error or warning appears in the widget.

initialized

Raised only once, after the widget is initialized.

nodesInitialized

Fires when all nodes in the widget are initialized.

nodesRendering

Fires before nodes will be displayed.

optionChanged

Raised after a widget option is changed.

selectionChanged

Fires when the selection state of a node has been changed.

See Also

Node

This section describes the Node object, which represents a treemap node.

Node objects are accessible within certain event handlers, for example, onNodesInitialized, onNodesRendering, etc. Also, you can obtain these objects using the getRootNode() and getCurrentNode() methods.