分组树图

该示例使用CollectionView显示分组的TreeMap。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; 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() { var treemap = new hierarchical.TreeMap('#chart', { binding: 'sales', bindingName: ['category', 'subCategory'], itemsSource: getData(), dataLabel: { position: 'Center', content: '{name}' } }); 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]]; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Grouped 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"> <div id="chart"></div> </div> </body> </html> // Get random data. import * as core from '@grapecity/wijmo'; export function getData() { var data = []; for (var i = 0; i < 1000; i++) { var catIndex = Math.floor(Math.random() * categories.length), subCategory = subCategories[catIndex], subIndex = Math.floor(Math.random() * subCategory.length); data.push({ category: categories[catIndex], subCategory: subCategory[subIndex], sales: getSales() }); } var cv = new core.CollectionView(data); cv.groupDescriptions.push(new core.PropertyGroupDescription('category')); cv.groupDescriptions.push(new core.PropertyGroupDescription('subCategory')); return cv; } // generate data for the sample 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); } 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 { WjChartHierarchicalModule } from '@grapecity/wijmo.angular2.chart.hierarchical'; import { DataService } from './app.data'; import * as core from '@grapecity/wijmo'; import * as chart from '@grapecity/wijmo.chart'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: core.CollectionView; bindingName: string[]; palette: any; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.bindingName = ['category', 'subCategory']; this.palette = this.getRandomPalette(); } // 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: [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 Grouped 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-tree-map binding="sales" [bindingName]="bindingName" [itemsSource]="data" labelContent="{name}" [palette]="palette"></wj-tree-map> </div> </div> import { Injectable } from '@angular/core'; import * as core from '@grapecity/wijmo'; // generate data for the sample 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 = []; for (var i = 0; i < 1000; i++) { var catIndex = Math.floor(Math.random() * categories.length), subCategory = subCategories[catIndex], subIndex = Math.floor(Math.random() * subCategory.length); data.push({ category: categories[catIndex], subCategory: subCategory[subIndex], sales: getSales() }); } var cv = new core.CollectionView(data); cv.groupDescriptions.push(new core.PropertyGroupDescription('category')); cv.groupDescriptions.push(new core.PropertyGroupDescription('subCategory')); return cv; } } body { margin-bottom: 24px; } <template> <div class="container-fluid"> <div class="form-group"> <wj-tree-map binding="sales" :bindingName="['category', 'subCategory']" :itemsSource="data" 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.chart'; 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(), palette: this.getRandomPalette() } }, methods: { 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 Grouped 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> import * as core from '@grapecity/wijmo'; // generate data for the sample 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 = []; for (var i = 0; i < 1000; i++) { var catIndex = Math.floor(Math.random() * categories.length), subCategory = subCategories[catIndex], subIndex = Math.floor(Math.random() * subCategory.length); data.push({ category: categories[catIndex], subCategory: subCategory[subIndex], sales: getSales() }); } var cv = new core.CollectionView(data); cv.groupDescriptions.push(new core.PropertyGroupDescription('category')); cv.groupDescriptions.push(new core.PropertyGroupDescription('subCategory')); return cv; } 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 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.state = { data: getData(), palette: this.getRandomPalette() }; } render() { return <div className="container-fluid"> <div className="form-group"> <wjHierarchical.TreeMap binding="sales" bindingName={['category', 'subCategory']} itemsSource={this.state.data} palette={this.state.palette} initialized={this.initTreemap}></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>AutoComplete</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; } import * as core from '@grapecity/wijmo'; // generate data for the sample 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 = []; for (var i = 0; i < 1000; i++) { var catIndex = Math.floor(Math.random() * categories.length), subCategory = subCategories[catIndex], subIndex = Math.floor(Math.random() * subCategory.length); data.push({ category: categories[catIndex], subCategory: subCategory[subIndex], sales: getSales() }); } var cv = new core.CollectionView(data); cv.groupDescriptions.push(new core.PropertyGroupDescription('category')); cv.groupDescriptions.push(new core.PropertyGroupDescription('subCategory')); return cv; }