行和列字段(维度)

PivotEngine 有几个字段集合作为属性公开:

  • fields:包含数据源中可用的所有字段。
  • valueFields:包含用作“度量”的字段,通常是引擎汇总的数值。
  • rowFieldscolumnFields:包含用作“维度”的字段,通常是用于将数据分组的字符串或日期。
  • filterFields:包含仅用于过滤数据的字段(它们不包含在输出摘要中)。

PivotEngine 确保每个维度字段仅在视图中出现一次。如果将“Buyer”字段拖到 columnFields 区域,它将自动从 rowFields 区域中删除。

PivotEngine 使用维度字段将数据分组。它使用格式化值来执行此操作,因此如果将日期字段格式化为年份(yyyy)或季度(q),则数据将按年或季度汇总。

如果您希望能够按年按季度汇总数据,请创建两个日期字段副本,每个字段具有不同的格式和标题。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjOlap from '@grapecity/wijmo.olap'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // initialize pivot engine var ngPanel = new wjOlap.PivotEngine({ itemsSource: getData(1000), valueFields: ['Amount'], rowFields: ['Buyer', 'Type'] // summarize amounts }); var amountField = ngPanel.fields.getField('Amount'); amountField.format = 'c0'; // customize field // // clone the date fields to show quarters var yearField = ngPanel.fields.getField('Date'); yearField.header = 'Year'; yearField.format = 'yyyy'; // var quarterField = new wjOlap.PivotField(ngPanel, 'date', 'Quarter'); quarterField.format = '"Q"q'; ngPanel.fields.splice(1, 0, quarterField); // // show pivot panel var pivotPanel = new wjOlap.PivotPanel('#pivotPanel', { itemsSource: ngPanel }); // // show summary var pivotPanelGrid = new wjOlap.PivotGrid('#pivotPanelGrid', { itemsSource: ngPanel }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Panel Row Column Fields</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 class="row"> <div class="col-xs-5"> <p> Drag and drop fields to build views: </p> <div id="pivotPanel"></div> </div> <div class="col-xs-7"> <p> Summary for the current view definition: </p> <div id="pivotPanelGrid"></div> </div> </div> </div> </body> </html> import * as wjCore from '@grapecity/wijmo'; // get the raw data // get the raw data export function getData(cnt) { var today = new Date(), buyers = 'Mom,Dad,Kelly,Sheldon'.split(','), types = 'Food,Clothes,Fuel,Books,Sports,Music'.split(','), data = []; for (var i = 0; i < cnt; i++) { data.push({ date: wjCore.DateTime.addDays(today, -Math.random() * 365 * 3), buyer: randomItem(buyers), type: randomItem(types), amount: 20 + Math.random() * 1000 }); } return data; } function randomItem(arr) { return arr[Math.floor(Math.random() * arr.length)]; } .wj-pivotpanel { background: #eee; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .wj-pivotpanel .wj-flexgrid { background: inherit; } .wj-pivotpanel [wj-part=d-rows], .wj-pivotpanel [wj-part=d-cols] { background: gold; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjOlap from '@grapecity/wijmo.olap'; // import { Component, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjOlapModule } from '@grapecity/wijmo.angular2.olap'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { ngPanel: wjOlap.PivotEngine; // constructor(@Inject(DataService) private dataService: DataService) { this.ngPanel = new wjOlap.PivotEngine({ itemsSource: dataService.getData(1000), // raw data valueFields: ['Amount'], // summarize amounts rowFields: ['Buyer', 'Type'] // summarize amounts }); this.ngPanel.fields.getField('Amount').format = 'c0'; // var yearField = this.ngPanel.fields.getField('Date'); yearField.header = 'Year'; yearField.format = 'yyyy'; // var quarterField = new wjOlap.PivotField(this.ngPanel, 'date', 'Quarter'); quarterField.format = '"Q"q'; this.ngPanel.fields.splice(1, 0, quarterField); } } // @NgModule({ imports: [WjOlapModule, 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 OLAP Pivot Panel Row Column Fields</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="row"> <div class="col-xs-5"> <p> Drag and drop fields to build views: </p> <wj-pivot-panel [itemsSource]="ngPanel"></wj-pivot-panel> </div> <div class="col-xs-7"> <p> Summary for the current view definition: </p> <wj-pivot-grid [itemsSource]="ngPanel"></wj-pivot-grid> </div> </div> </div> import * as wjCore from '@grapecity/wijmo'; import { Injectable } from '@angular/core'; export interface DataItem { date: Date; buyer: string; type: string; amount: number; } function randomItem(arr: string[]) { return arr[Math.floor(Math.random() * arr.length)]; } @Injectable() export class DataService { getData(cnt: number): DataItem[] { var today = new Date(), buyers = 'Mom,Dad,Kelly,Sheldon'.split(','), types = 'Food,Clothes,Fuel,Books,Sports,Music'.split(','), data = []; for (var i = 0; i < cnt; i++) { data.push({ date: wjCore.DateTime.addDays(today, -Math.random() * 365 * 3), buyer: randomItem(buyers), type: randomItem(types), amount: 20 + Math.random() * 1000 }); } return data; } } .wj-pivotpanel { background: #eee; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .wj-pivotpanel .wj-flexgrid { background: inherit; } .wj-pivotpanel [wj-part=d-rows], .wj-pivotpanel [wj-part=d-cols] { background: gold; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <div class="row"> <div class="col-xs-5"> <p> Drag and drop fields to build views: </p> <wj-pivot-panel id="sample-panel" :items-source="ngPanel"></wj-pivot-panel> </div> <div class="col-xs-7"> <p> Summary for the current view definition: </p> <wj-pivot-grid :items-source="ngPanel"></wj-pivot-grid> </div> </div> </div> </template> <script> import '@grapecity/wijmo.styles/wijmo.css'; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.olap'; import * as wjcOlap from '@grapecity/wijmo.olap'; import { getData } from './data' let App = Vue.extend({ name: "app", data: function() { return { ngPanel: new wjcOlap.PivotEngine({ itemsSource: getData(1000), // raw data valueFields: ['Amount'], // summarize amounts rowFields: ['Buyer', 'Type'] // summarize amounts }) }; }, mounted: function() { this.ngPanel.fields.getField('Amount').format = 'c0'; let yearField = this.ngPanel.fields.getField('Date'); yearField.header = 'Year'; yearField.format = 'yyyy'; let quarterField = new wjcOlap.PivotField(this.ngPanel, 'date', 'Quarter'); quarterField.format = '"Q"q'; this.ngPanel.fields.splice(1, 0, quarterField); } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> #sample-panel { background: #eee; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } #sample-panel .wj-flexgrid { background: inherit; } #sample-panel [wj-part=d-rows], #sample-panel [wj-part=d-cols] { background: gold; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Panel Row Column Fields</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 wjcCore from '@grapecity/wijmo'; export function getData(cnt) { var today = new Date(), buyers = 'Mom,Dad,Kelly,Sheldon'.split(','), types = 'Food,Clothes,Fuel,Books,Sports,Music'.split(','), data = []; for (var i = 0; i < cnt; i++) { data.push({ date: wjcCore.DateTime.addDays(today, -Math.random() * 365 * 3), buyer: randomItem(buyers), type: randomItem(types), amount: 20 + Math.random() * 1000 }); } return data; } function randomItem(arr) { return arr[Math.floor(Math.random() * arr.length)]; } import './app.css'; import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as Olap from '@grapecity/wijmo.react.olap'; import * as wjcOlap from '@grapecity/wijmo.olap'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.state = { ngPanel: new wjcOlap.PivotEngine({ itemsSource: getData(1000), valueFields: ['Amount'], rowFields: ['Buyer', 'Type'] // summarize amounts }) }; } componentDidMount() { this.state.ngPanel.fields.getField('Amount').format = 'c0'; let yearField = this.state.ngPanel.fields.getField('Date'); yearField.header = 'Year'; yearField.format = 'yyyy'; let quarterField = new wjcOlap.PivotField(this.state.ngPanel, 'date', 'Quarter'); quarterField.format = '"Q"q'; this.state.ngPanel.fields.splice(1, 0, quarterField); } render() { return (<div className="container-fluid"> <div className="row"> <div className="col-xs-5"> <p> Drag and drop fields to build views: </p> <Olap.PivotPanel id="sample-panel" itemsSource={this.state.ngPanel}></Olap.PivotPanel> </div> <div className="col-xs-7"> <p> Summary for the current view definition: </p> <Olap.PivotGrid itemsSource={this.state.ngPanel}></Olap.PivotGrid> </div> </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> #sample-panel { background: #eee; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23); } #sample-panel .wj-flexgrid { background: inherit; } #sample-panel [wj-part=d-rows], #sample-panel [wj-part=d-cols] { background: gold; } body { margin-bottom: 24pt; } import * as wjcCore from '@grapecity/wijmo'; export function getData(cnt) { var today = new Date(), buyers = 'Mom,Dad,Kelly,Sheldon'.split(','), types = 'Food,Clothes,Fuel,Books,Sports,Music'.split(','), data = []; for (var i = 0; i < cnt; i++) { data.push({ date: wjcCore.DateTime.addDays(today, -Math.random() * 365 * 3), buyer: randomItem(buyers), type: randomItem(types), amount: 20 + Math.random() * 1000 }); } return data; } function randomItem(arr) { return arr[Math.floor(Math.random() * arr.length)]; }