Loading...
Loading...
Implement Syncfusion Windows Forms TreeMap control for hierarchical data visualization with nested rectangles. Use this when working with TreeMap controls, hierarchical data display, space-efficient charts, or color-coded visualizations. Covers TreeMap configuration, layout algorithms, color mapping, and customization for stock market visualizations and data categorization with rectangular layouts.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-treemapInstall-Package Syncfusion.TreeMap.WinFormsusing System.Collections.ObjectModel;
public class PopulationDetail
{
public string Continent { get; set; }
public string Country { get; set; }
public double Growth { get; set; }
public double Population { get; set; }
}
public class PopulationViewModel
{
public ObservableCollection<PopulationDetail> PopulationDetails { get; set; }
public PopulationViewModel()
{
PopulationDetails = new ObservableCollection<PopulationDetail>();
PopulationDetails.Add(new PopulationDetail
{
Continent = "Asia",
Country = "Indonesia",
Growth = 3,
Population = 237641326
});
PopulationDetails.Add(new PopulationDetail
{
Continent = "Asia",
Country = "Russia",
Growth = 2,
Population = 152518015
});
PopulationDetails.Add(new PopulationDetail
{
Continent = "North America",
Country = "United States",
Growth = 4,
Population = 315645000
});
// Add more data...
}
}using Syncfusion.Windows.Forms.TreeMap;
public class MyForm : Form
{
private TreeMap treeMap;
public MyForm()
{
InitializeComponent();
// Create TreeMap instance
treeMap = new TreeMap();
// Set data source
PopulationViewModel data = new PopulationViewModel();
treeMap.ItemsSource = data.PopulationDetails;
// Configure paths
treeMap.WeightValuePath = "Population";
treeMap.ColorValuePath = "Growth";
// Set layout mode
treeMap.ItemsLayoutMode = ItemsLayoutModes.Squarified;
// Add first level (Continent)
TreeMapFlatLevel level1 = new TreeMapFlatLevel();
level1.GroupPath = "Continent";
level1.ShowLabels = true;
treeMap.Levels.Add(level1);
// Add second level (Country)
TreeMapFlatLevel level2 = new TreeMapFlatLevel();
level2.GroupPath = "Country";
level2.ShowLabels = true;
level2.HeaderHeight = 25;
treeMap.Levels.Add(level2);
// Add color mapping
UniColorMapping colorMapping = new UniColorMapping();
colorMapping.Color = Color.MediumSlateBlue;
treeMap.LeafColorMapping = colorMapping;
// Set size and add to form
treeMap.Size = new Size(800, 600);
treeMap.Location = new Point(10, 10);
this.Controls.Add(treeMap);
}
}// Create levels for nested grouping
TreeMapFlatLevel level1 = new TreeMapFlatLevel();
level1.GroupPath = "Category";
level1.ShowLabels = true;
treeMap.Levels.Add(level1);
TreeMapFlatLevel level2 = new TreeMapFlatLevel();
level2.GroupPath = "SubCategory";
level2.ShowLabels = true;
level2.HeaderHeight = 25;
treeMap.Levels.Add(level2);
TreeMapFlatLevel level3 = new TreeMapFlatLevel();
level3.GroupPath = "Item";
level3.ShowLabels = true;
level3.HeaderHeight = 20;
treeMap.Levels.Add(level3);RangeBrushColorMapping rangeMapping = new RangeBrushColorMapping();
rangeMapping.Brushes.Add(new RangeBrush
{
Color = ColorTranslator.FromHtml("#77D8D8"),
From = 0,
To = 1,
LegendLabel = "Low"
});
rangeMapping.Brushes.Add(new RangeBrush
{
Color = ColorTranslator.FromHtml("#FFAF51"),
From = 1,
To = 5,
LegendLabel = "Medium"
});
rangeMapping.Brushes.Add(new RangeBrush
{
Color = ColorTranslator.FromHtml("#F3D240"),
From = 5,
To = 20,
LegendLabel = "High"
});
treeMap.LeafColorMapping = rangeMapping;// Enable tooltips
treeMap.IsToolTipVisible = true;
// Configure header tooltip
ToolTipInfo headerToolTip = new ToolTipInfo();
headerToolTip.ToolTipHeaderPattern = "<b>{Label}</b>";
headerToolTip.ToolTipContentPattern = "Growth: {Growth}%";
treeMap.HeaderToolTipInfo = headerToolTip;
// Configure item tooltip
ToolTipInfo itemToolTip = new ToolTipInfo();
itemToolTip.ToolTipHeaderPattern = "<b>{Country}</b>";
itemToolTip.ToolTipContentPattern = "Growth: {Growth}%\nPopulation: {Population}";
treeMap.ItemToolTipInfo = itemToolTip;| Property | Type | Description |
|---|---|---|
| object | Data collection to visualize |
| string | Path to field determining rectangle size |
| string | Path to field for color mapping |
| ItemsLayoutModes | Layout algorithm selection |
| TreeMapLevelCollection | Collection of hierarchical levels |
| TreeMapColorMapping | Color mapping strategy |
| Property | Type | Description |
|---|---|---|
| Font | Font for leaf node labels |
| Brush | Label text color |
| Brush | Label background color |
| Brush | Label border color |
| int | Label border width |
| Brush | Header background color |
| Property | Type | Description |
|---|---|---|
| LegendPositions | Legend placement (Top/Bottom/Left/Right) |
| LegendTypes | Legend icon shape |
| int | Spacing between legend items |
| Property | Type | Description |
|---|---|---|
| bool | Enable/disable tooltips |
| ToolTipInfo | Tooltip configuration for headers |
| ToolTipInfo | Tooltip configuration for leaf items |
level.ShowLabels = trueTreeMap.LeafColorMappingSyncfusion.TreeMap.WinFormsSyncfusion.TreeMap.WindowsSyncfusion.Windows.Forms.TreeMapSyncfusion.TreeMap.WinForms