Horizontal & Vertical TreeMap

The sample shows a horizontal and vertical TreeMap.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as input from '@grapecity/wijmo.input'; import * as chart from '@grapecity/wijmo.chart'; import * as hierarchical from '@grapecity/wijmo.chart.hierarchical'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // change chart type var typeMenu = new input.Menu('#typeMenu', { itemClicked: function (s, e) { treemap.type = parseInt(s.selectedValue); updateMenuHeader(s, 'Type'); } }); updateMenuHeader(typeMenu, 'Type'); // var treemap = new hierarchical.TreeMap('#chart', { binding: 'sales', bindingName: ['category', 'subCategory'], itemsSource: getData(), dataLabel: { position: 'Center', content: '{name}' }, type: hierarchical.TreeMapType.Squarified }); treemap.palette = getRandomPalette(); } // function getRandomPalette() { let palettes = Object.getOwnPropertyNames(chart.Palettes) .filter(prop => typeof chart.Palettes[prop] === "object" && prop !== 'prototype'); let rand = Math.floor(Math.random() * palettes.length); // return chart.Palettes[palettes[rand]]; } // show menu header and current value function updateMenuHeader(menu, header) { menu.header = header ? header + ': <b>' + menu.text + '</b>' : menu.text; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Horizontal & Vertical TreeMap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <select id="typeMenu"> <option value="0" selected="selected">Squarified</option> <option value="1">Horizontal</option> <option value="2">Vertical</option> </select> <div id="chart"></div> </div> </body> </html> // Get random data. var categories = ['Beverages', 'Condiments', 'Confections', 'Dairy Products', 'Grains/Cereals', 'Meat/Poultry', 'Produce', 'Seafood']; var subCategories = [ ['Soft drinks', 'Coffees', 'Teas', 'Beers', 'Ales'], ['Sweet and Savory sauces', 'Relishes', 'Spreads', 'Seasonings'], ['Desserts', 'Candies', 'Sweet breads'], ['Cheeses'], ['Breads', 'Crackers', 'Pasta', 'Cereal'], ['Prepared meats'], ['Dried fruit', 'Bean curd'], ['Seaweed', 'Fish'] ]; function getSales() { return Math.round(Math.random() * 100); } export function getData() { var data = []; categories.forEach(function (category, index) { subCategories[index].forEach(function (subCategory) { data.push({ category: category, subCategory: subCategory, sales: getSales() }); }); }); return data; } body { margin-bottom: 24px; } .wj-flexchart { height: 500px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { WjChartHierarchicalModule } from '@grapecity/wijmo.angular2.chart.hierarchical'; import * as input from '@grapecity/wijmo.input'; import * as chart from '@grapecity/wijmo.chart'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; palette: any; bindingName: string[]; type: any; selectedValue: string; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.palette = this.getRandomPalette(); this.bindingName = ['category', 'subCategory']; this.type = "Squarified"; } // getRandomPalette() { let palettes = Object.getOwnPropertyNames(chart.Palettes) .filter(prop => typeof chart.Palettes[prop] === "object" && prop !== 'prototype'); let rand = Math.floor(Math.random() * palettes.length); // return chart.Palettes[palettes[rand]]; } } // @NgModule({ imports: [WjInputModule, WjChartHierarchicalModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Horizontal & Vertical TreeMap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="form-group"> <wj-menu #typeMenu header="Type" [(value)]="type"> <wj-menu-item value="Squarified">Squarified</wj-menu-item> <wj-menu-item value="Horizontal">Horizontal</wj-menu-item> <wj-menu-item value="Vertical">Vertical</wj-menu-item> </wj-menu> <wj-tree-map binding="sales" [bindingName]="bindingName" [itemsSource]="data" [type]="type" labelContent="{name}" [palette]="palette"> </wj-tree-map> </div> </div> import { Injectable } from '@angular/core'; // Get random data. var categories = ['Beverages', 'Condiments', 'Confections', 'Dairy Products', 'Grains/Cereals', 'Meat/Poultry', 'Produce', 'Seafood']; var subCategories = [ ['Soft drinks', 'Coffees', 'Teas', 'Beers', 'Ales'], ['Sweet and Savory sauces', 'Relishes', 'Spreads', 'Seasonings'], ['Desserts', 'Candies', 'Sweet breads'], ['Cheeses'], ['Breads', 'Crackers', 'Pasta', 'Cereal'], ['Prepared meats'], ['Dried fruit', 'Bean curd'], ['Seaweed', 'Fish'] ]; function getSales() { return Math.round(Math.random() * 100); } // @Injectable() export class DataService { getData() { var data: any[] = []; categories.forEach(function (category, index) { subCategories[index].forEach(function (subCategory) { data.push({ category: category, subCategory: subCategory, sales: getSales() }); }); }); return data; } } body { margin-bottom: 24px; } <template> <div class="container-fluid"> <div class="form-group"> <wj-menu :header="'Type: ' + type" :selectedValue="type" :itemClicked="menuItemClicked" :itemsSource="menuData"> </wj-menu> <wj-tree-map binding="sales" :bindingName="['category', 'subCategory']" :itemsSource="data" :type="type" labelContent="{name}" :palette="palette"> </wj-tree-map> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; import '@grapecity/wijmo.vue2.chart.hierarchical'; import { getData } from './data'; import * as wjChart from '@grapecity/wijmo.chart'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), menuData: ['Squarified', 'Horizontal', 'Vertical'], palette: this.getRandomPalette(), type: 'Squarified' } }, methods: { menuItemClicked: function(menu) { this.type = menu.selectedValue; }, getRandomPalette: function() { let palettes = Object.getOwnPropertyNames(wjChart.Palettes) .filter(prop => typeof wjChart.Palettes[prop] === "object" && prop !== 'prototype'); let rand = Math.floor(Math.random() * palettes.length); // return wjChart.Palettes[palettes[rand]]; } } }) new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> body { margin-bottom: 24px; } label { margin-right: 3px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Horizontal & Vertical TreeMap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> // Get random data. var categories = ['Beverages', 'Condiments', 'Confections', 'Dairy Products', 'Grains/Cereals', 'Meat/Poultry', 'Produce', 'Seafood']; var subCategories = [ ['Soft drinks', 'Coffees', 'Teas', 'Beers', 'Ales'], ['Sweet and Savory sauces', 'Relishes', 'Spreads', 'Seasonings'], ['Desserts', 'Candies', 'Sweet breads'], ['Cheeses'], ['Breads', 'Crackers', 'Pasta', 'Cereal'], ['Prepared meats'], ['Dried fruit', 'Bean curd'], ['Seaweed', 'Fish'] ]; function getSales() { return Math.round(Math.random() * 100); } export function getData() { var data = []; categories.forEach(function (category, index) { subCategories[index].forEach(function (subCategory) { data.push({ category: category, subCategory: subCategory, sales: getSales() }); }); }); return data; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as chart from '@grapecity/wijmo.chart'; import * as wjInput from '@grapecity/wijmo.react.input'; import * as wjHierarchical from '@grapecity/wijmo.react.chart.hierarchical'; import { getData } from './data'; // class App extends React.Component { constructor(props) { super(props); this.initTreemap = (sender) => { sender.dataLabel.content = "{name}"; }; this.getRandomPalette = () => { let palettes = Object.getOwnPropertyNames(chart.Palettes) .filter(prop => typeof chart.Palettes[prop] === "object" && prop !== 'prototype'); let rand = Math.floor(Math.random() * palettes.length); // return chart.Palettes[palettes[rand]]; }; this.menuItemClicked = (menu) => { this.setState({ type: menu.selectedValue }); }; this.state = { data: getData(), menuData: ['Squarified', 'Horizontal', 'Vertical'], palette: this.getRandomPalette(), type: 'Squarified' }; } render() { return <div className="container-fluid"> <div className="form-group"> <wjInput.Menu header={'Type: ' + this.state.type} selectedValue={this.state.type} itemClicked={this.menuItemClicked} itemsSource={this.state.menuData}> </wjInput.Menu> <wjHierarchical.TreeMap binding="sales" bindingName={['category', 'subCategory']} type={this.state.type} initialized={this.initTreemap} itemsSource={this.state.data} palette={this.state.palette} maxDepth={this.state.maxDepth}> </wjHierarchical.TreeMap> </div> </div>; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Horizontal & Vertical TreeMap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> body { margin-bottom: 24px; } // Get random data. var categories = ['Beverages', 'Condiments', 'Confections', 'Dairy Products', 'Grains/Cereals', 'Meat/Poultry', 'Produce', 'Seafood']; var subCategories = [ ['Soft drinks', 'Coffees', 'Teas', 'Beers', 'Ales'], ['Sweet and Savory sauces', 'Relishes', 'Spreads', 'Seasonings'], ['Desserts', 'Candies', 'Sweet breads'], ['Cheeses'], ['Breads', 'Crackers', 'Pasta', 'Cereal'], ['Prepared meats'], ['Dried fruit', 'Bean curd'], ['Seaweed', 'Fish'] ]; function getSales() { return Math.round(Math.random() * 100); } export function getData() { var data = []; categories.forEach(function (category, index) { subCategories[index].forEach(function (subCategory) { data.push({ category: category, subCategory: subCategory, sales: getSales() }); }); }); return data; }