Highcharts Tutorial
Chart Types
Highcharts Treemap is a chart type used to represent hierarchical data in a rectangular layout. The size and color of each rectangle are used to represent the values of the data. The rectangles are nested inside each other to represent the hierarchy.
To create a treemap chart in Highcharts, you can use the chart.type
option set to 'treemap'
. The data for the chart should be in a hierarchical format, with each data point having a name
and value
property. If you want to display a nested hierarchy, you can include a children
property with an array of child data points.
Here's an example of how to create a basic treemap chart in Highcharts:
Highcharts.chart('container', { chart: { type: 'treemap' }, title: { text: 'Treemap Chart' }, series: [{ type: 'treemap', layoutAlgorithm: 'squarified', data: [{ name: 'Category 1', value: 10 }, { name: 'Category 2', value: 20 }, { name: 'Category 3', value: 30 }] }] });
In this example, we first create a Highcharts chart object and configure it with the following options:
chart.type
is set to 'treemap'
to create a treemap charttitle.text
is set to 'Treemap Chart'
to set the main titleseries
is set to an array of objects with a type
, layoutAlgorithm
, and data
property to define the series data. The type
property is set to 'treemap'
to specify the chart type, the layoutAlgorithm
property is set to 'squarified'
to specify the layout algorithm to use, and the data
property contains an array of objects with name
and value
properties.With these options, you can create a basic treemap chart in Highcharts. You can also customize the chart further by adding additional data points, setting the color scheme and style of the chart, and configuring the layout algorithm to optimize the representation of your data.
Customizing Highcharts Treemap:
Highcharts.chart('container', { series: [{ type: 'treemap', data: [...], // Treemap data layoutAlgorithm: 'squarified', // Set layout algorithm color: '#7CB5EC', // Set default color borderColor: 'black', // Set border color borderWidth: 2 // Set border width }], // Other configuration options... });
Interactive Treemaps with Highcharts:
Highcharts.chart('container', { series: [{ type: 'treemap', allowDrillToNode: true, // Enable drilldown to node dataLabels: { enabled: true // Show data labels }, // Other configuration options... }], // Other configuration options... });
Highcharts Treemap data format:
name
and value
properties.data: [{ name: 'Category 1', value: 10 }, { name: 'Category 2', value: 15 }],
Highcharts Treemap drilldown example:
drilldown
series.series: [{ type: 'treemap', data: [...], drilldown: { series: [{ name: 'Subcategory 1', id: 'subcategory1', data: [...] }] } }],
Highcharts Treemap color options:
color
option or a color axis.colorAxis: { minColor: '#FFFFFF', maxColor: '#7CB5EC' },
Highcharts Treemap hierarchical data:
data: [{ name: 'Category 1', value: 10, children: [{ name: 'Subcategory 1', value: 5 }] }],
Highcharts Treemap tooltip customization:
tooltip: { pointFormat: '<b>{point.name}</b>: {point.value}' },
Highcharts Treemap integration with JavaScript:
Highcharts.chart('container', { chart: { events: { load: function () { // Handle chart load event } } }, // Other configuration options... });
Highcharts Treemap responsive design:
responsive
option.responsive: { rules: [{ condition: { maxWidth: 500 }, // Adjust options for smaller screens }] },
Highcharts Treemap with JSON data:
series: [{ type: 'treemap', data: { // JSON data } }],
Highcharts Treemap events handling:
series: [{ type: 'treemap', point: { events: { click: function () { // Handle click event } } }, // Other configuration options... }],