TreeMap

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

Included in: dx.viz.js, dx.viz-web.js, dx.all.js
Module: viz/tree_map
Export: default
TreeMap interactive configuration
Copy Code
Copy to Codepen
$("#treemap").dxTreeMap({
});

                    

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.

You can create the TreeMap widget using one of the following approaches.

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)
)

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the topics in the Installation section.

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 handler for the drawn event.

onDrill

A handler for the drill event.

onExported

A handler for the exported event.

onExporting

A handler for the exporting event.

onFileSaving

A handler for the fileSaving event.

onHoverChanged

A handler for the hoverChanged event.

onIncidentOccurred

A handler for the incidentOccurred event.

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

Specifies whether or not the widget supports right-to-left representation.

selectionMode

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

size

Specifies the size of the widget in pixels.

theme

Sets the name of the theme to be used in the widget.

tile

Configures tiles.

title

Specifies the widget title.

tooltip

Configures tooltips.

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.

drillUp()

Drills one level up.

element()

Gets the root element of the widget.

endUpdate()

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

exportTo(fileName, format)

Exports the widget into a document with a specified name and format.

getCurrentNode()

Returns the current node.

getDataSource()

Returns the DataSource instance.

getRootNode()

Returns the root node.

getSize()

Gets the current size of the widget.

hideLoadingIndicator()

Conceals the loading indicator.

hideTooltip()

Hides the tooltip.

instance()

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

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Gets the widget's options.

option(optionName)

Gets a specific option value.

option(optionName, optionValue)

Assigns a new value to a specific option.

option(options)

Sets one or more options.

print()

Opens the browser's print window.

render()

Redraws the widget.

resetDrillDown()

Resets the drill down level.

showLoadingIndicator()

Displays the loading indicator.

svg()

Returns 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

Fires when the widget has finished drawing itself.

drill

Fires when the user drills up or down.

exported

Fires after data from the widget is exported.

exporting

Fires before data from the widget is exported.

fileSaving

Fires 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

Fires when an error or warning appears in a 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 an option of the widget 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.