syncfusion-angular-treemap
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion Angular TreeMap
实现Syncfusion Angular TreeMap
The TreeMap component visualizes hierarchical or grouped data as nested rectangles. Each rectangle represents a data item, and its size is determined by a numeric field mapped through . TreeMaps are useful for displaying structures such as product categories, regional breakdowns, market segments, or any grouped dataset where relative magnitude matters.
weightValuePathTreeMap组件将层级或分组数据可视化为嵌套矩形。每个矩形代表一个数据项,其大小由通过映射的数字字段决定。TreeMap适用于展示产品类别、区域细分、市场细分等结构,或任何相对量级重要的分组数据集。
weightValuePathWhen to Use This Skill
何时使用此技能
- Visualizing hierarchical data: Display grouped or multi-level data such as regions, departments, or product categories
- Multi-level data visualization: Show parent-child relationships using and
levelsgroupPath - Creating drill-down interfaces: Enable interactive navigation through hierarchy levels
- Color-coding data: Use range, equal, desaturation, palette, or direct color binding
- Adding interactive features: Implement selection, highlight, click, double-click, and right-click interactions
- Customizing appearance: Modify layout, colors, borders, labels, headers, legends, and templates
- Displaying supplementary information: Add labels, tooltips, legends, and formatted values
- Exporting visualizations: Print or export as PNG, JPEG, SVG, or PDF
- International support: Enable RTL, locale-specific number formatting, and culture-aware display
- Accessibility: Improve screen reader support, ARIA naming, contrast, and focus behavior
- 可视化层级数据:展示区域、部门或产品类别等分组或多级数据
- 多级数据可视化:使用和
levels展示父子关系groupPath - 创建钻取界面:启用层级间的交互式导航
- 数据颜色编码:使用范围、相等、饱和度调整、调色板或直接颜色绑定
- 添加交互功能:实现选择、高亮、单击、双击和右键交互
- 自定义外观:修改布局、颜色、边框、标签、标题、图例和模板
- 展示补充信息:添加标签、工具提示、图例和格式化值
- 导出可视化内容:打印或导出为PNG、JPEG、SVG或PDF格式
- 国际化支持:启用RTL、区域特定数字格式和文化感知显示
- 无障碍功能:提升屏幕阅读器支持、ARIA命名、对比度和焦点行为
Documentation and Navigation Guide
文档与导航指南
Choose your reference based on what you need to accomplish:
根据你的需求选择参考文档:
API Reference
API参考
📄 Read:
references/api-reference.md📄 阅读:
references/api-reference.mdGetting Started
快速入门
📄 Read:
references/getting-started.md- Installation and npm package setup
- Importing
TreeMapModule - Creating your first TreeMap component
- Theme and style configuration
- Basic component with simple data
📄 阅读:
references/getting-started.md- 安装与npm包设置
- 导入
TreeMapModule - 创建你的第一个TreeMap组件
- 主题与样式配置
- 带简单数据的基础组件
Data Binding
数据绑定
📄 Read:
references/data-binding.md- Binding flat collections
- Grouping data with
levels - Mapping data source properties to TreeMap fields
- Configuring for item sizing
weightValuePath - Dynamic data updates and state-driven binding
📄 阅读:
references/data-binding.md- 绑定扁平集合
- 使用分组数据
levels - 将数据源属性映射到TreeMap字段
- 配置用于项大小设置
weightValuePath - 动态数据更新与状态驱动绑定
Color Mapping
颜色映射
📄 Read:
references/color-mapping.md- Range color mapping for numeric values
- Equal color mapping for category-based colors
- Desaturation color mapping with opacity
- Palette-based coloring
- Direct color binding with
colorValuePath - Gradient colors with
leafItemSettings.colorMapping
📄 阅读:
references/color-mapping.md- 数值的范围颜色映射
- 基于类别的相等颜色映射
- 带透明度的饱和度调整颜色映射
- 基于调色板的着色
- 使用直接颜色绑定
colorValuePath - 通过实现渐变色
leafItemSettings.colorMapping
Drilldown and Navigation
钻取与导航
📄 Read:
references/drilldown-and-navigation.md- Enabling drilldown functionality
- Parent-child navigation with
levels - behavior
drillDownView - Breadcrumb navigation
- Drill events (,
drillStart)drillEnd - Resetting to root through application state when needed
📄 阅读:
references/drilldown-and-navigation.md- 启用钻取功能
- 使用实现父子导航
levels - 行为
drillDownView - 面包屑导航
- 钻取事件(、
drillStart)drillEnd - 必要时通过应用状态重置到根层级
Levels and Layout
层级与布局
📄 Read:
references/levels-and-layout.md- Configuring multiple hierarchy levels
- and grouped rendering
groupPath - Layout types (,
Squarified,SliceAndDiceVertical,SliceAndDiceHorizontal)SliceAndDiceAuto - Group spacing and leaf gaps
- Header formatting and styling
- Header templates and header sizing
📄 阅读:
references/levels-and-layout.md- 配置多个层级
- 与分组渲染
groupPath - 布局类型(、
Squarified、SliceAndDiceVertical、SliceAndDiceHorizontal)SliceAndDiceAuto - 组间距与叶子项间隙
- 标题格式化与样式
- 标题模板与标题大小
Labels, Tooltips, and Legend
标签、工具提示与图例
📄 Read:
references/labels-tooltips-legend.md- Data label configuration and formatting
- Label templates and template positioning
- Handling label intersections and overflow
- Tooltip visibility and formatting
- Custom tooltip templates
- Legend display and configuration
- Coordinating legend with color mapping, selection, and highlight
📄 阅读:
references/labels-tooltips-legend.md- 数据标签配置与格式化
- 标签模板与模板定位
- 处理标签交叉与溢出
- 工具提示可见性与格式化
- 自定义工具提示模板
- 图例显示与配置
- 协调图例与颜色映射、选择和高亮
Selection and Interactivity
选择与交互性
📄 Read:
references/selection-interactivity.md- Enabling selection and highlight
- Customizing selection colors and borders
- Legend-based selection and hover interaction
- Click, item-selected, double-click, and right-click events
- Programmatic selection with
selectItem(...) - Managing single-item or multi-item workflows in application state
📄 阅读:
references/selection-interactivity.md- 启用选择与高亮
- 自定义选择颜色与边框
- 基于图例的选择与悬停交互
- 单击、项选中、双击和右键事件
- 使用进行程序化选择
selectItem(...) - 在应用状态中管理单项或多项工作流
Print, Export, and Accessibility
打印、导出与无障碍功能
📄 Read:
references/print-export-accessibility.md- Print functionality
- Image export (PNG, JPEG, SVG)
- PDF export with orientation options
- Base64 export handling
- WCAG accessibility support
- Screen reader support and ARIA labels
- Contrast and focus considerations
📄 阅读:
references/print-export-accessibility.md- 打印功能
- 图片导出(PNG、JPEG、SVG)
- 带方向选项的PDF导出
- Base64导出处理
- WCAG无障碍支持
- 屏幕阅读器支持与ARIA标签
- 对比度与焦点注意事项
Internationalization
国际化
📄 Read:
references/internationalization.md- Right-to-left (RTL) rendering
- Locale configuration and number formatting
- Globalization for labels and tooltips
- Render direction configuration
- Multi-language data binding
- Cultural customization with and
setCulture()setCurrencyCode()
📄 阅读:
references/internationalization.md- 从右到左(RTL)渲染
- 区域配置与数字格式化
- 标签与工具提示的全球化
- 渲染方向配置
- 多语言数据绑定
- 使用和
setCulture()进行文化自定义setCurrencyCode()
Quick Start
快速开始
typescript
import { Component, signal } from '@angular/core';
import { TreeMapModule } from '@syncfusion/ej2-angular-treemap';
@Component({
selector: 'app-treemap',
standalone: true,
imports: [TreeMapModule],
template: `
<ejs-treemap
id="treemap-container"
[dataSource]="data()"
weightValuePath="Size"
[levels]="levels"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>
`,
styles: [`
#treemap-container {
display: block;
width: 100%;
height: 500px;
}
`]
})
export class TreeMapComponent {
public data = signal([
{ Category: 'Electronics', Item: 'Laptops', Size: 150 },
{ Category: 'Electronics', Item: 'Phones', Size: 200 },
{ Category: 'Furniture', Item: 'Chairs', Size: 100 },
{ Category: 'Furniture', Item: 'Tables', Size: 120 }
]);
public levels = [
{ groupPath: 'Category' }
];
public leafItemSettings = {
labelPath: 'Item',
gap: 4,
border: { color: '#ffffff', width: 1 }
};
}typescript
import { Component, signal } from '@angular/core';
import { TreeMapModule } from '@syncfusion/ej2-angular-treemap';
@Component({
selector: 'app-treemap',
standalone: true,
imports: [TreeMapModule],
template: `
<ejs-treemap
id="treemap-container"
[dataSource]="data()"
weightValuePath="Size"
[levels]="levels"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>
`,
styles: [`
#treemap-container {
display: block;
width: 100%;
height: 500px;
}
`]
})
export class TreeMapComponent {
public data = signal([
{ Category: 'Electronics', Item: 'Laptops', Size: 150 },
{ Category: 'Electronics', Item: 'Phones', Size: 200 },
{ Category: 'Furniture', Item: 'Chairs', Size: 100 },
{ Category: 'Furniture', Item: 'Tables', Size: 120 }
]);
public levels = [
{ groupPath: 'Category' }
];
public leafItemSettings = {
labelPath: 'Item',
gap: 4,
border: { color: '#ffffff', width: 1 }
};
}Common Patterns
常见模式
Pattern 1: Basic Hierarchical Visualization
模式1:基础层级可视化
Display grouped hierarchical data using and .
levelsgroupPathtypescript
public levels = [
{ groupPath: 'Region', headerFormat: '${Region}' },
{ groupPath: 'Country', headerFormat: '${Country}' }
];
public leafItemSettings = {
labelPath: 'Country'
};使用和展示分组层级数据。
levelsgroupPathtypescript
public levels = [
{ groupPath: 'Region', headerFormat: '${Region}' },
{ groupPath: 'Country', headerFormat: '${Country}' }
];
public leafItemSettings = {
labelPath: 'Country'
};Pattern 2: Color-Mapped Values
模式2:颜色映射值
Use range color mapping through and .
rangeColorValuePathleafItemSettings.colorMappingtypescript
<ejs-treemap
[dataSource]="data()"
weightValuePath="Value"
rangeColorValuePath="Value"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>typescript
public leafItemSettings = {
labelPath: 'Name',
colorMapping: [
{ from: 0, to: 50, color: '#3498db' },
{ from: 50, to: 100, color: '#e74c3c' }
]
};通过和使用范围颜色映射。
rangeColorValuePathleafItemSettings.colorMappingtypescript
<ejs-treemap
[dataSource]="data()"
weightValuePath="Value"
rangeColorValuePath="Value"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>typescript
public leafItemSettings = {
labelPath: 'Name',
colorMapping: [
{ from: 0, to: 50, color: '#3498db' },
{ from: 50, to: 100, color: '#e74c3c' }
]
};Pattern 3: Interactive Drilldown
模式3:交互式钻取
Enable drilldown with breadcrumb navigation for exploring grouped levels.
typescript
<ejs-treemap
[dataSource]="data()"
weightValuePath="Value"
[enableDrillDown]="true"
[enableBreadcrumb]="true"
breadcrumbConnector=" / "
[levels]="levels"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>启用钻取并搭配面包屑导航,用于探索分组层级。
typescript
<ejs-treemap
[dataSource]="data()"
weightValuePath="Value"
[enableDrillDown]="true"
[enableBreadcrumb]="true"
breadcrumbConnector=" / "
[levels]="levels"
[leafItemSettings]="leafItemSettings">
</ejs-treemap>Key Props and Configuration
关键属性与配置
| Property | Type | Purpose |
|---|---|---|
| | Data collection for TreeMap items |
| | Numeric field used to size each item |
| | Leaf item configuration such as labels, borders, templates, and color mapping |
| | Hierarchy configuration using |
| | Rectangle arrangement algorithm |
| | Data field used for direct item color assignment |
| | Data field used for category-based color mapping |
| | Data field used for numeric range color mapping |
| | Enables drilldown navigation through grouped levels |
| | Displays breadcrumb navigation during drilldown |
| | Legend display and styling configuration |
| | Tooltip visibility, formatting, and template configuration |
| | Selection appearance and behavior configuration |
| | Hover highlight appearance configuration |
| | Enables right-to-left rendering |
| | Overrides the component culture |
| | Applies numeric formatting such as |
| | Enables culture-aware number grouping separators |
| | Enables print support |
| | Enables image export support |
| | Enables PDF export support |
| | Adds descriptive accessibility text for the component |
| | Controls focus order for the TreeMap container |
| 属性 | 类型 | 用途 |
|---|---|---|
| | TreeMap项的数据集合 |
| | 用于设置每个项大小的数字字段 |
| | 叶子项配置,如标签、边框、模板和颜色映射 |
| | 使用 |
| | 矩形排列算法 |
| | 用于直接分配项颜色的数据字段 |
| | 用于基于类别颜色映射的数据字段 |
| | 用于数值范围颜色映射的数据字段 |
| | 启用分组层级间的钻取导航 |
| | 钻取期间显示面包屑导航 |
| | 图例显示与样式配置 |
| | 工具提示可见性、格式化和模板配置 |
| | 选择外观与行为配置 |
| | 悬停高亮外观配置 |
| | 启用从右到左渲染 |
| | 覆盖组件文化设置 |
| | 应用数值格式化,如 |
| | 启用文化感知的数字分组分隔符 |
| | 启用打印支持 |
| | 启用图片导出支持 |
| | 启用PDF导出支持 |
| | 为组件添加描述性无障碍文本 |
| | 控制TreeMap容器的焦点顺序 |
Implementation Notes
实现注意事项
- Prefer for focused standalone Angular components.
TreeMapModule - Use ,
TreeMapLegendService,TreeMapTooltipService,TreeMapSelectionService,TreeMapHighlightService,PrintService, andImageExportServiceonly when the corresponding features are enabled.PdfExportService - For color mapping, configure and pair it with
leafItemSettings.colorMappingorequalColorValuePathwhen needed.rangeColorValuePath - For programmatic selection, use rather than unsupported helper methods.
selectItem(levelOrder, isSelected?) - For accessibility, rely on TreeMap’s built-in ARIA support, meaningful titles, labels, legends, descriptions, and strong color contrast.
- For keyboard and advanced interaction workflows, provide surrounding Angular controls where needed rather than assuming extra undocumented TreeMap keyboard APIs.
- 对于聚焦的独立Angular组件,优先使用。
TreeMapModule - 仅在启用对应功能时,才使用、
TreeMapLegendService、TreeMapTooltipService、TreeMapSelectionService、TreeMapHighlightService、PrintService和ImageExportService。PdfExportService - 颜色映射方面,配置,必要时搭配
leafItemSettings.colorMapping或equalColorValuePath。rangeColorValuePath - 程序化选择请使用,而非不支持的辅助方法。
selectItem(levelOrder, isSelected?) - 无障碍功能方面,依赖TreeMap内置的ARIA支持、有意义的标题、标签、图例、描述和高颜色对比度。
- 对于键盘和高级交互工作流,需在周边提供Angular控件,而非依赖未文档化的TreeMap额外键盘API。