計算の種類

PivotField.showAsプロパティを使用すると、フィールド値が表示される前にそのフィールド値に対して実行される一般的な計算を指定できます。このプロパティのオプションはShowAs列挙体によって定義され、前の行または列の値との差分、行、列、総計、積算合計に対するパーセンテージが含まれます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjOlap from '@grapecity/wijmo.olap'; import * as wjInput from '@grapecity/wijmo.input'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // initialize pivot engine var ng = new wjOlap.PivotEngine({ autoGenerateFields: false, fields: [ { binding: 'date', header: '年', format: 'yyyy' }, { binding: 'date', header: '月', format: 'MMM' }, { binding: 'buyer', header: '担当者' }, { binding: 'type', header: '分類' }, { binding: 'amount', header: '金額', format: 'c0', aggregate: 'Sum' }, { binding: 'amount', header: '計算の種類', format: 'c0', aggregate: 'Sum' }, ], itemsSource: getData(1000), showRowTotals: 'Subtotals', valueFields: ['金額', '計算の種類'], rowFields: ['年', '月'] // by Year and Quarter }); // // show summary var pivotGrid = new wjOlap.PivotGrid('#pivotGrid', { itemsSource: ng }); // // change the setting of the ShowAs property var fld = ng.fields.getField('計算の種類'); var showAs = new wjInput.ComboBox('#showAs', { itemsSource: '計算なし,前の行との差分,前の行との差分の比率,前の列との差分,前の列との差分の比率,総合計の %,行の合計の %,列の合計の %,実行中の合計,積算合計の %,前の行との比率,前の列との比率'.split(','), text: wjOlap.ShowAs[fld.showAs], textChanged: function (s, e) { fld.showAs = s.selectedIndex; fld.format = s.text.endsWith('%') || s.text.endsWith('比率') ? 'p0' : 'c0'; } }); // // show period in columns or in rows document.getElementById('periodInColumns').addEventListener('click', function (e) { var list = e.target.checked ? ng.columnFields : ng.rowFields; list.push('月'); }); // } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Fields Show as Functions</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="pivotGrid"></div> <p> フィールドの<b>showAs</b>プロパティの値を変更します。 </p> <input id="showAs"><br/> <p> <label> 列で期間を表示 <input id="periodInColumns" type="checkbox"> </label> </p> </div> </body> </html> import * as wjCore from '@grapecity/wijmo'; // get the raw data export function getData(cnt) { var today = new Date(), buyers = '成宮 真紀,山本 雅治,加藤 泰江,川村 匡'.split(','), types = '音楽,ビデオ,本,家電,パソコン,食品'.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)]; } .container > label { width: 120px; text-align: right; } .container > .wj-control { margin-bottom: 6px; } .wj-flexgrid { height: 200px; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjOlap from '@grapecity/wijmo.olap'; import * as wjInput from '@grapecity/wijmo.input'; // 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 { WjOlapModule } from '@grapecity/wijmo.angular2.olap'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { ng: wjOlap.PivotEngine; fld: wjOlap.PivotField; showAsOptions: string[]; showAsText: string; // constructor(@Inject(DataService) private dataService: DataService) { this.ng = new wjOlap.PivotEngine({ autoGenerateFields: false, // turn off auto-generation fields: [ // specify the fields we want (no date) { binding: 'date', header: '年', format: 'yyyy' }, { binding: 'date', header: '月', format: 'MMM' }, { binding: 'buyer', header: '担当者' }, { binding: 'type', header: '分類' }, { binding: 'amount', header: '金額', format: 'c0', aggregate: 'Sum' }, { binding: 'amount', header: '計算の種類', format: 'c0', aggregate: 'Sum' }, ], itemsSource: dataService.getData(1000), // raw data showRowTotals: 'Subtotals', valueFields: ['金額', '計算の種類'], // show amount spent rowFields: ['年', '月'] // by Year and Quarter }); this.fld = this.ng.fields.getField('計算の種類'); this.showAsText = wjOlap.ShowAs[this.fld.showAs]; // this.showAsOptions = '計算なし,前の行との差分,前の行との差分の比率,前の列との差分,前の列との差分の比率,総合計の %,行の合計の %,列の合計の %,実行中の合計,積算合計の %,前の行との比率,前の列との比率'.split(','); } // onTextChanged(combox: wjInput.ComboBox) { this.fld.showAs = combox.selectedIndex; this.fld.format = combox.text.endsWith('%') || combox.text.endsWith('比率') ? 'p0' : 'c0'; } // onPeriodInColumns(e: MouseEvent) { let list = (e.target as HTMLInputElement).checked ? this.ng.columnFields : this.ng.rowFields; list.push('月'); } } // @NgModule({ imports: [WjOlapModule, WjInputModule, 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 Fields Show as Functions</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"> <wj-pivot-grid [itemsSource]="ng"></wj-pivot-grid> <p> フィールドの<b>showAs</b>プロパティの値を変更します。 </p> <wj-combo-box #combo [itemsSource]="showAsOptions" [text]="showAsText" (textChanged)="onTextChanged(combo)"></wj-combo-box> <p> <label> 列で期間を表示 <input id="periodInColumns" type="checkbox" (click)="onPeriodInColumns($event)"> </label> </p> </div> import { Injectable } from '@angular/core'; import * as wjCore from '@grapecity/wijmo'; export interface DataItem { date: Date; buyer: string; type: string; amount: number; } function randomItem(arr: string[]): string { return arr[Math.floor(Math.random() * arr.length)]; } @Injectable() export class DataService { getData(cnt: number): DataItem[] { var today = new Date(), buyers = '成宮 真紀,山本 雅治,加藤 泰江,川村 匡'.split(','), types = '音楽,ビデオ,本,家電,パソコン,食品'.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; } } .container > label { width: 120px; text-align: right; } .container > .wj-control { margin-bottom: 6px; } .wj-flexgrid { height: 200px; } body { margin-bottom: 24pt; } 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 wjInput from '@grapecity/wijmo.react.input'; import * as wjcOlap from '@grapecity/wijmo.olap'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.state = { ng: new wjcOlap.PivotEngine({ autoGenerateFields: false, fields: [ { binding: 'date', header: '年', format: 'yyyy' }, { binding: 'date', header: '月', format: 'MMM' }, { binding: 'buyer', header: '担当者' }, { binding: 'type', header: '分類' }, { binding: 'amount', header: '金額', format: 'c0', aggregate: 'Sum' }, { binding: 'amount', header: '計算の種類', format: 'c0', aggregate: 'Sum' }, ], itemsSource: getData(1000), showRowTotals: 'Subtotals', valueFields: ['金額', '計算の種類'], rowFields: ['年', '月'] // by Year and Quarter }), showAsOptions: '計算なし,前の行との差分,前の行との差分の比率,前の列との差分,前の列との差分の比率,総合計の %,行の合計の %,列の合計の %,実行中の合計,積算合計の %,前の行との比率,前の列との比率'.split(',') }; this.fld = this.state.ng.fields.getField('計算の種類'); } render() { return (<div className="container-fluid"> <Olap.PivotGrid itemsSource={this.state.ng}></Olap.PivotGrid> <p> フィールドの<b>showAs</b>プロパティの値を変更します。 </p> <wjInput.ComboBox itemsSource={this.state.showAsOptions} textChanged={this.onTextChanged.bind(this)}></wjInput.ComboBox> <p> <label> 列で期間を表示 <input id="periodInColumns" type="checkbox" onClick={this.onPeriodInColumns.bind(this)}/> </label> </p> </div>); } onTextChanged(combox) { this.fld.showAs = wjcOlap.ShowAs[combox.selectedIndex]; this.fld.format = combox.text.endsWith('%') || combox.text.endsWith('比率') ? 'p0' : 'c0'; } onPeriodInColumns(e) { let list = e.target.checked ? this.state.ng.columnFields : this.state.ng.rowFields; list.push('月'); } } 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> .container>label { width: 120px; text-align: right; } .container>.wj-control { margin-bottom: 6px; } .wj-flexgrid { height: 200px; } body { margin-bottom: 24pt; } import * as wjcCore from '@grapecity/wijmo'; export function getData(cnt) { var today = new Date(), buyers = '成宮 真紀,山本 雅治,加藤 泰江,川村 匡'.split(','), types = '音楽,ビデオ,本,家電,パソコン,食品'.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)]; } <template> <div class="container-fluid"> <wj-pivot-grid :items-source="ng"></wj-pivot-grid> <p> フィールドの<b>showAs</b>プロパティの値を変更します。 </p> <wj-combo-box :items-source="showAsOptions" :textChanged="onTextChanged"></wj-combo-box> <p> <label> 列で期間を表示 <input id="periodInColumns" type="checkbox" v-on:click="onPeriodInColumns"> </label> </p> </div> </template> <script> import '@grapecity/wijmo.styles/wijmo.css'; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.input'; 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 { ng: new wjcOlap.PivotEngine({ autoGenerateFields: false, // turn off auto-generation fields: [ // specify the fields we want (no date) { binding: 'date', header: '年', format: 'yyyy' }, { binding: 'date', header: '月', format: 'MMM' }, { binding: 'buyer', header: '担当者' }, { binding: 'type', header: '分類' }, { binding: 'amount', header: '金額', format: 'c0', aggregate: 'Sum' }, { binding: 'amount', header: '計算の種類', format: 'c0', aggregate: 'Sum' }, ], itemsSource: getData(1000), // raw data showRowTotals: 'Subtotals', valueFields: ['金額', '計算の種類'], // show amount spent rowFields: ['年', '月'] // by Year and Quarter }), showAsOptions: '計算なし,前の行との差分,前の行との差分の比率,前の列との差分,前の列との差分の比率,総合計の %,行の合計の %,列の合計の %,実行中の合計,積算合計の %,前の行との比率,前の列との比率'.split(',') }; }, mounted: function(){ this.fld = this.ng.fields.getField('計算の種類'); }, methods: { onTextChanged(combox) { this.fld.showAs = wjcOlap.ShowAs[combox.selectedIndex]; this.fld.format = combox.text.endsWith('%') || combox.text.endsWith('比率') ? 'p0' : 'c0'; }, onPeriodInColumns(e) { let list = e.target.checked ? this.ng.columnFields : this.ng.rowFields; list.push('月'); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .container > label { width: 120px; text-align: right; } .container > .wj-control { margin-bottom: 6px; } .wj-flexgrid { height: 200px; } 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 Fields Show as Functions</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 = '成宮 真紀,山本 雅治,加藤 泰江,川村 匡'.split(','), types = '音楽,ビデオ,本,家電,パソコン,食品'.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)]; }