Framework:Javascript Data GridAngular Data GridReact Data GridVue Data Grid

Angular Charts: Treemap Series

Treemap series is used to render hierarchical data structures or trees, where each node in the tree is represented by a rectangle, and the value of a node by the area of its rectangle.

The bigger the value, the bigger the rectangle is relative to its siblings. Parent nodes are represented by rectangles with areas that are the totals of their children.

If the nodes have no value, then their area is divided equally among siblings within their parent node.

The Ag Charts treemap series uses a popular "squarified" tiling algorithm which tries to keep each node's rectangle as square as possible.

Treemap series would be a great fit for visualizing a directory structure (the original purpose of the algorithm), components of a stock market index, shares of products within product categories, or sales breakdown by city, state, and country. And these are just a few examples.

Basic Configuration

cartesian and polar charts are used with linear data or, in other words, arrays. Since treemaps are used to render tree data, to create a basic treemap, we need to use a hierarchy chart.

A basic treemap configuration would look like this:

type: 'hierarchy',
data, // the root node of the hierarchy
series: [{
    type: 'treemap',
    labelKey: 'label', // the name of the key to fetch the label value from
    sizeKey: 'size',   // the name of the key to fetch the value that will determine tile size
    colorKey: 'color', // the name of the key to fetch the value that will determine tile color
}]

The data should be a tree structure, where parent nodes use the children property to list their children:

let data = {
    label: 'Root',
    children: [
        {
            label: 'Utilities',
            children: [{
                label: 'AWK',
                size: 252
            }]
        },
        ...
    ]
}

Notice, that only the leaf nodes of a tree are required to have the sizeKey property. The size of the parent nodes will be automatically determined.

The labelKey, sizeKey and colorKey configs can be omitted, if the node objects in your data happen to have the label, size and color fields.

Any treemap series covers the whole series area of a chart, so it doesn't make sense to have more than a single treemap series in a chart, even though it's technically supported.

Let's take a look at how we can use the treemap series to render a snapshot of the S&P 500 stock market index. Feel free to open this example in Plunker to enlarge the size of the component and notice how the treemap reveals more data as it grows bigger.

Stock Market Index Example

Alternative Configuration

Although not very common, treemaps can be used to show the hierarchy without emphasizing size. In such a case, you can set the sizeKey to undefined. This will make all sibling tiles within the same parent have the same area (but not necessarily the same shape).

The org chart example below takes advantage of that by using the following config:

series: [{
    type: 'treemap',
    labelKey: 'orgHierarchy',
    sizeKey: undefined,  // make all siblings within a parent the same size
    colorKey: undefined, // use node depth value to determine the tile color
    colorParents: true,  // assign color to parent tiles based on their depth too (not just leaf tiles)
    colorDomain: [0, 2, 4], // depth of 0 will correspond to 'red', 2 to 'green' and so on
    colorRange: ['red', 'green', 'blue'] // tiles with a depth of 1 will be a blend of 'red' and 'green'
}]

Organizational Chart Example

API Reference

Properties available on the AgTreemapSeriesOptions interface.

type
'treemap'
'treemap'
title
AgTreemapSeriesLabelOptions
The label configuration for the top-level tiles.
title: AgTreemapSeriesLabelOptions;

interface AgTreemapSeriesLabelOptions {
  // The amount of the tile's vertical space to reserve for the label. 
  padding?: number;
  // Whether or not the labels should be shown. 
  enabled?: boolean;
  // The font style to use for the labels. 
  fontStyle?: FontStyle;
  // The font weight to use for the labels. 
  fontWeight?: FontWeight;
  // The font size in pixels to use for the labels. 
  fontSize?: FontSize;
  // The font family to use for the labels. 
  fontFamily?: FontFamily;
  // The colour to use for the labels. 
  color?: CssColor;
}

type FontStyle = 
      'normal' 
    | 'italic' 
    | 'oblique'


type FontWeight = 
      'normal' 
    | 'bold' 
    | 'bolder' 
    | 'lighter' 
    | '100' 
    | '200' 
    | '300' 
    | '400' 
    | '500' 
    | '600' 
    | '700' 
    | '800' 
    | '900'


type FontSize = number

type FontFamily = string

type CssColor = string
subtitle
AgTreemapSeriesLabelOptions
The label configuration for the children of the top-level parent tiles.
subtitle: AgTreemapSeriesLabelOptions;

interface AgTreemapSeriesLabelOptions {
  // The amount of the tile's vertical space to reserve for the label. 
  padding?: number;
  // Whether or not the labels should be shown. 
  enabled?: boolean;
  // The font style to use for the labels. 
  fontStyle?: FontStyle;
  // The font weight to use for the labels. 
  fontWeight?: FontWeight;
  // The font size in pixels to use for the labels. 
  fontSize?: FontSize;
  // The font family to use for the labels. 
  fontFamily?: FontFamily;
  // The colour to use for the labels. 
  color?: CssColor;
}

type FontStyle = 
      'normal' 
    | 'italic' 
    | 'oblique'


type FontWeight = 
      'normal' 
    | 'bold' 
    | 'bolder' 
    | 'lighter' 
    | '100' 
    | '200' 
    | '300' 
    | '400' 
    | '500' 
    | '600' 
    | '700' 
    | '800' 
    | '900'


type FontSize = number

type FontFamily = string

type CssColor = string
labels
AgTreemapSeriesLabelsOptions
Configuration for the tile labels.
labels: AgTreemapSeriesLabelsOptions;

interface AgTreemapSeriesLabelsOptions {
  // The label configuration for the large leaf tiles. 
  large?: AgChartLabelOptions;
  // The label configuration for the medium-sized leaf tiles. 
  medium?: AgChartLabelOptions;
  // The label configuration for the small leaf tiles. 
  small?: AgChartLabelOptions;
  // The configuration for the labels showing the value of the 'colorKey'. 
  color?: AgChartLabelOptions;
}

interface AgChartLabelOptions {
  // Whether or not the labels should be shown. 
  enabled?: boolean;
  // The font style to use for the labels. 
  fontStyle?: FontStyle;
  // The font weight to use for the labels. 
  fontWeight?: FontWeight;
  // The font size in pixels to use for the labels. 
  fontSize?: FontSize;
  // The font family to use for the labels. 
  fontFamily?: FontFamily;
  // The colour to use for the labels. 
  color?: CssColor;
}

type FontStyle = 
      'normal' 
    | 'italic' 
    | 'oblique'


type FontWeight = 
      'normal' 
    | 'bold' 
    | 'bolder' 
    | 'lighter' 
    | '100' 
    | '200' 
    | '300' 
    | '400' 
    | '500' 
    | '600' 
    | '700' 
    | '800' 
    | '900'


type FontSize = number

type FontFamily = string

type CssColor = string
labelKey
string
The name of the node key containing the label.
Default: 'label'
sizeKey
string
The name of the node key containing the size value.
Default: 'size'
colorKey
string
The name of the node key containing the color value. This value (along with colorDomain and colorRange configs) will be used to determine the tile color.
Default: 'color'
colorDomain
number[]
The domain the 'colorKey' values belong to. The domain can contain more than two stops, for example [-5, 0, -5]. In that case the 'colorRange' should also use a matching number of colors.
Default: [-5, 5]
colorRange
string[]
The color range to interpolate the numeric colorDomain into. For example, if the colorDomain is [-5, 5] and colorRange is ['red', 'green'], a colorKey value of -5 will be assigned the 'red' color, 5 - 'green' color and 0 a blend of 'red' and 'green'.
Default: ['#cb4b3f', '#6acb64']
colorParents
boolean
Whether or not to assign colors to non-leaf nodes based on 'colorKey'.
Default: false
tooltip
AgTreemapSeriesTooltip
Series-specific tooltip configuration.
tooltip: AgTreemapSeriesTooltip;

interface AgTreemapSeriesTooltip {
  // Function used to create the content for tooltips. 
  renderer?: (params: AgTreemapSeriesTooltipRendererParams) => string | AgTooltipRendererResult;
  // Whether or not to show tooltips when the series are hovered over. 
  enabled?: boolean;
}

interface AgTreemapSeriesTooltipRendererParams {
  datum: AgTreemapNodeDatum;
  sizeKey: string;
  labelKey: string;
  valueKey: string;
  color: string;
}

interface AgTreemapNodeDatum {
  datum: any;
  parent?: AgTreemapNodeDatum;
  children?: AgTreemapNodeDatum[];
  depth: number;
  colorValue: number;
  fill: CssColor;
  label: string;
  hasTitle: boolean;
}

type CssColor = string

interface AgTooltipRendererResult {
  title?: string;
  content?: string;
}
nodePadding
PixelSize
The amount of padding in pixels inside of each treemap tile. Increasing nodePadding will reserve more space for parent labels.
nodePadding: PixelSize;

type PixelSize = number
gradient
boolean
Whether or not to use gradients for treemap tiles.
Default: true
data
any[]
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visible
boolean
Whether or not to display the series.
showInLegend
boolean
Whether or not to include the series in the legend.
cursor
string
The cursor to use for hovered area markers. This config is identical to the CSS cursor property.
listeners
AgBaseSeriesListeners | {[key: string]: Function}
A map of event names to event listeners.
listeners: AgBaseSeriesListeners | {[key: string]: Function};

interface AgBaseSeriesListeners {
  // The listener to call when a node (marker, column, bar, tile or a pie slice) in the series is clicked. 
  nodeClick: (params: { type: 'nodeClick'; series: any; datum: any; xKey: string; yKey: string; }) => any;
}
highlightStyle
AgSeriesHighlightStyle
Configuration for series markers and series line highlighting when a marker / data point or a legend item is hovered over.
highlightStyle: AgSeriesHighlightStyle;

interface AgSeriesHighlightStyle {
  // Highlight style used for an individual marker when tapped or hovered over. 
  item?: AgSeriesHighlightMarkerStyle;
  // Highlight style used for whole series when one of its markers is tapped or hovered over. 
  series?: AgSeriesHighlightSeriesStyle;
}

interface AgSeriesHighlightMarkerStyle {
  // The fill colour of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  fill?: CssColor;
  // The stroke colour of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  stroke?: CssColor;
  // The stroke width of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  strokeWidth?: PixelSize;
}

type CssColor = string

type PixelSize = number

interface AgSeriesHighlightSeriesStyle {
  enabled?: boolean;
  // The opacity of the whole series (area line, area fill, labels and markers, if any) when another chart series or another stack level in the same area series is highlighted by hovering a data point or a legend item. Use `undefined` or `1` for no dimming. 
  dimOpacity?: Opacity;
  // The stroke width of the area line when one of the markers is tapped or hovered over, or when a tooltip is shown for a data point, even when series markers are disabled. Use `undefined` for no highlight. 
  strokeWidth?: PixelSize;
}

type Opacity = number

Next Up

Continue to the next section to learn about combination charts.