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
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 flat 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
    Use the dxTreeMap jQuery plug-in.

    HTML
    <div id="treeMapContainer"></div>
    JavaScript
    $("#treeMapContainer").dxTreeMap({
        dataSource: data,
        labelField: 'text',
        valueField: 'val'
    });
  • Knockout
    Add a div element and apply dxTreeMap binding to this element.

    HTML
    <div data-bind="dxTreeMap: {
        dataSource: data,
        labelField: 'text',
        valueField: 'val'
    }"></div>
  • AngularJS
    Add a div element and apply the dx-tree-map directive to this element.

    HTML
    <div dx-tree-map="{
        dataSource: data,
        labelField: 'text',
        valueField: 'val'
    }"></div>

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 Installation article.

View Demo Watch Video

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.

export

Configures the exporting and printing features.

group

Configures groups.

hoverEnabled

Specifies whether tiles and groups change their style in the hover state.

idField

Specifies the name of the data source field that provides IDs for items. Applies to flat 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.

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.

onNodesInitialized

A handler for the nodesInitialized event.

onNodesRendering

A handler for the nodesRendering event.

onOptionChanged

A handler for the optionChanged event.

onSelectionChanged

A handler for the selectionChanged event.

parentField

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

pathModified

Notifies a widget that it is embedded into an HTML page that uses a path modifier.

redrawOnResize

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

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 component from refreshing until the endUpdate() method is called.

clearSelection()

Deselects all nodes in the widget.

drillUp()

Drills one level up.

element()

Returns the root HTML element of the widget.

endUpdate()

Enables the component to refresh after the beginUpdate() method call.

exportTo(fileName, format)

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

getCurrentNode()

Returns the current node.

getRootNode()

Returns the root node.

hideLoadingIndicator()

Conceals the loading indicator.

hideTooltip()

Hides the tooltip.

instance()

Returns an instance of this component class.

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

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

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

Fires when the widget is being removed.

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

Fires when the widget is initialized.

nodesInitialized

Fires when all nodes in the widget are initialized.

nodesRendering

Fires before nodes will be displayed.

optionChanged

Fires after an option of the component is changed.

selectionChanged

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

Node

This section describes fields and methods that can be used in code to manipulate a Node object.

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.