Skip to main content
RSS feed Subscribe to feed


Creating a Treemap

Code examples explaining how to set up treemaps.

Refer to What is a Treemap? for a treemap presentation.

Create and Configure a Treemap

public static void CreateTreemap(AnalysisApplication application)
    LoadDataAndConfigurePage(application, "worldsales.txt");

    // Add a Treemap
    Treemap treemap = application.Document.ActivePageReference.Visuals.AddNew<Treemap>();
    treemap.Title = "Treemap - Sales per region";

    // Connect the treemap to data
    DataManager dataManager = application.Document.Data;
    treemap.Data.DataTableReference = dataManager.Tables.DefaultTableReference;

    // Set filtering for the visualization
    treemap.Data.UseActiveFiltering = true;

    // Set marking for the visualization
    treemap.Data.MarkingReference = dataManager.Markings.DefaultMarkingReference;

    // Set hierarchy
    treemap.HierarchyAxis.Expression = "<Continent NEST Country NEST City>";

    // Set size by total sales
    treemap.SizeAxis.Expression = "Sum(Sales) AS [Total Sales]";

    // Color by the most recent sale
    treemap.ColorAxis.Expression = "Last([Date of Sale]) AS [Most Recent Sale]";

    // Hide the legend item for the hierarchy. The hierarchy is visible through
    // headers anyway.
    treemap.HierarchyAxis.LegendItem.Visible = false;

    // Finally zoom to show only Asia
    treemap.HierarchyAxis.ZoomPath = new CategoryKey("Asia");