Wijmo UI for the Web
Quick Start
Wijmo User Guide > Widgets > TreeMap > Quick Start

In this quick start, you'll learn how to add the wijtreemap widget to an HTML project using HTML markup and jQuery script.

  1. To create a new HTML page in your favorite text editor, add the following code and save the document with an .html extension.

    Drop down and copy markup

    Paste in your favorite text editor.
    Copy Code
    <!DOCTYPE HTML>
    <HTML>
    <head>
    </head>
    <body>
    </body>
    </HTML>
    
  2. Add links to the dependencies to your HTML page within the <head> tags. Find the latest dependencies in the content delivery network (CDN) file at wijmo cdn.

    Drop down and copy references to paste inside the head tags

    References
    Copy Code
    <!--Theme-->
    <link href="http://cdn.wijmo.com/themes/aristo/jquery-wijmo.css" rel="stylesheet" type="text/css" />
    
    <!--Wijmo Widgets CSS-->
    <link href="http://cdn.wijmo.com/jquery.wijmo-pro.all.3.20183.140.min.css" rel="stylesheet" type="text/css" />
    
    <!--RequireJs-->
    <script type="text/javascript" src="http://cdn.wijmo.com/external/require.js"></script>
    
    <script type="text/javascript">
        requirejs.config({
            baseUrl: "http://cdn.wijmo.com/amd-js/3.20183.140",
            paths: {
                "jquery": "jquery-1.11.1.min",
                "jquery-ui": "jquery-ui-1.11.0.custom.min",
                "jquery.ui": "jquery-ui",
                "jquery.mousewheel": "jquery.mousewheel.min",
                "globalize": "globalize.min"
            }
        });
    </script>
  3. Add the following markup within the <body> tags to create the widget. The <div> element creates the widget and sets its height and width.

    Drop down and copy markup to paste inside the body tags

    Markup
    Copy Code
          <h3 style="text-align: center">Area in Square Kilometers</h3>
         <div id="treemap" style="width:800px;height:400px;"></div>
    <p>The above treemap uses statistics provided by <a href = http://simple.wikipedia.org/wiki/List_of_countries_by_area> Wikipedia </a> </p> 
  4. Within the <head> tags, below the references, add the following script to initialize the widget and add data to be displayed.

    Drop down and copy markup to paste inside the head tags

    Markup
    Copy Code
    <script id="scriptInit" type="text/javascript">
        require(["wijmo.wijtreemap"], function () {
            $(document).ready(function () {
                $("#treemap").wijtreemap({
                    showTooltip: true,
    
                    maxColor: "#FF3300",
                    minColor: "#FFFF66",
                    midColor: "#99FF33",
                    maxColorValue: 45000000,
                    minColorValue: 950000,
                    midColorValue: 4000000,
    
                    data: [{
                        label: "Asia",
                        value: 44579000,
                        minColor: "#B2E0FF",
                        maxColor: "#0099FF",
                        midColor: "#66C2FF",
                        items: [{
                            label: "Central Asia",
                            value: 4003451
                        }, {
                            label: "Eastern Asia",
                            value: 11839074,
                            items: [{
                                label: "China",
                                value: 9596961
                            }, {
                                label: "Japan",
                                value: 377944
                            }, {
                                label: "Others",
                                value: 1864169
                            }]
                        }, {
                            label: "South-East Asia",
                            value: 4500000
                        }, {
                            label: "Western Asia",
                            value: 6255160
                        }, {
                            label: "Southern Asia",
                            value: 17981315,
                            items: [{
                                label: "India",
                                value: 3287590
                            }, {
                                label: "Others",
                                value: 14693725
                            }]
                        }]
                    }, {
                        label: "Africa",
                        value: 30221532,
                        minColor: "#FFFFC2",
                        maxColor: "#CCCC52",
                        midColor: "#FFFF75",
                        items: [{
                            label: "Northern Africa",
                            value: 8935659,
                            items: [{
                                label: "Egypt",
                                value: 1002450
                            }, {
                                label: "Morocco",
                                value: 33250000
                            }]
                        }, {
                            label: "Central Africa",
                            value: 6612667
                        }, {
                            label: "Western Africa",
                            value: 5112903
                        }, {
                            label: "Southern Africa",
                            value: 1221037
                        }, {
                            label: "Eastern Africa",
                            value: 8339266
                        }]
                    }, {
                        label: "Americas",
                        value: 42549000,
                        minColor: "    #C2FFC2",
                        maxColor: "    #52CC52",
                        midColor: "    #94FF94",
                        items: [{
                            label: "South America",
                            value: 17840000,
                            items: [{
                                label: "Brazil",
                                value: 8515767
                            }, {
                                label: "Argentina",
                                value: 2780400
                            }, {
                                label: "Peru",
                                value: 1285216
                            }, {
                                label: "Colombia",
                                value: 1141748
                            }, {
                                label: "Others",
                                value: 4116869
                            }]
                        }, {
                            label: "North America",
                            value: 24709000,
                            items: [{
                                label: "Canada",
                                value: 9984670
                            }, {
                                label: "United States",
                                value: 9629091
                            }, {
                                label: "Greenland",
                                value: 2166086
                            }, {
                                label: "Mexico",
                                value: 1972550
                            }, {
                                label: "Others",
                                value: 956603
                            }]
                        }]
                    }, {
                        label: "Europe",
                        value: 10180000,
                        minColor: "#FFCC99",
                        maxColor: "#E68A2E",
                        midColor: "#FFAD5C",
                        items: [{
                            label: "Ukraine",
                            value: 603628
                        }, {
                            label: "Spain",
                            value: 504645
                        }, {
                            label: "France",
                            value: 640679
                        }, {
    
                            label: "Sweden",
                            value: 449964
                        }, {
                            label: "Others",
                            value: 7981084
                        }]
                    }, {
                        label: "Oceania",
                        value: 8525989,
                        minColor: "#00FFFF",
                        maxColor: "#4DFFFF",
                        midColor: "#33FFFF",
                        items: [{
                            label: "Australia",
                            value: 7692024
                        }, {
                            label: "NewZealand",
                            value: 268021
                        }, {
                            label: "others",
                            value: 565944
                        }]
                    }, {
                        label: "Antartica",
                        value: 14000000
                    }]
                })
            });
    
    
        })
    </script>
  5. The widget appears like the following live widget. Click a region to go to its child node. Right click to return to the parent node. The statistics given in the follwing example uses data provided by wikipedia.

See Also

Reference

How To