Treemap in C#
Render treemaps in C# with AddTreemap — proportional rectangles for part-of-whole with many categories. Self-contained SVG from .NET.
Treemap
AddTreemap() — nested rectangles sized proportionally.
When to use a treemap
Reach for it when
- Part-of-whole with too many categories for a pie chart — twenty or more still works.
- Where relative magnitude across a wide dynamic range should be visible at once.
- Space-constrained layouts; a treemap fills its rectangle completely.
Use something else when
- Comparing similarly-sized items. Rectangles of different aspect ratios are hard to compare by area.
- Negative or zero values, which have no area to draw.
- Change over time — the layout reshuffles between periods and the reader loses track of items.
Treemap in C#
Lifted verbatim from the chart types reference, so it compiles against the shipped API. See the API reference for every overload and the exact data types each series method accepts.
string svg = ChartBuilder.Create()
.Title("Portfolio Allocation")
.Size(700, 420)
.XAxis("Asset",
"US Equities","EU Equities","EM Equities",
"Gov Bonds", "Corp Bonds",
"Real Estate","Commodities","Cash")
.AsAnimated()
.Series(s => s
.AddTreemap("Allocation",
new double[] { 3200, 1800, 900, 1500, 1100, 700, 400, 300 }))
.RenderToSvg();Install
dotnet add package TerraFluent.Chart.Reporting
- MIT licensed — free for commercial use, no chart limits, no watermarks.
- Zero dependencies — nothing but the .NET base class library.
- netstandard2.0 through net10.0 — .NET Framework 4.6.1+, .NET Core 2.0+, and every modern release.
- Output is one SVG string — embed it in HTML, a PDF, or a Word document.