ソート

FlexChartを使用すると、表形式のデータをビジネスチャートとして視覚化できます。選択、ズーム、ドリルダウン、書式設定など、データの表示方法や対話式操作に関するさまざまなオプションを提供します。

すべてのWijmoコントロールと同様に、チャートはすべてのデータ関連タスクをCollectionViewクラスに委譲します。そのため、CollectionViewを使用して、データをフィルター、ソート、またはグループ化することができます。FlexChartは、列がシリーズで表され、行がグラフ上のデータ点である特別なタイプのデータグリッドと考えることもできます。

チャートのitemsSourceプロパティを配列またはObservableArrayに設定すると、チャートは自動的に元の配列をラップするCollectionViewインスタンスを作成します。このCollectionViewは、collectionViewプロパティで公開されアクセスすることができます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjChart from '@grapecity/wijmo.chart'; import * as wjCore from '@grapecity/wijmo'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the chart let theChart = new wjChart.FlexChart('#theChart', { itemsSource: getData(), bindingX: 'country', series: [ { binding: 'sales', name: '売上' }, { binding: 'expenses', name: '費用' }, { binding: 'downloads', name: 'DL数' } ] }); // // connect sort buttons sortOnClick('btnNone', null); sortOnClick('btnCountry', 'country'); sortOnClick('btnSales', 'sales'); sortOnClick('btnExpenses', 'expenses'); sortOnClick('btnDownloads', 'downloads'); // function sortOnClick(id, prop) { document.getElementById(id).addEventListener('click', () => { let sd = theChart.collectionView.sortDescriptions; // sd.clear(); sd.push(new wjCore.SortDescription(prop, true)); }); } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Sorting</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"> <p> ソート: <button id="btnNone" class="btn btn-default">なし</button> <button id="btnCountry" class="btn btn-default">国</button> <button id="btnSales" class="btn btn-default">売上</button> <button id="btnExpenses" class="btn btn-default">費用</button> <button id="btnDownloads" class="btn btn-default">DL数</button> </p> <div id="theChart"></div> </div> </body> </html> // create some random data export function getData() { let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], sales: Math.random() * 10000, expenses: Math.random() * 5000, downloads: Math.round(Math.random() * 20000) }); } // return data; } .wj-flexgrid { height: 150px; margin-top:10px; } .wj-flexchart { height: 300px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, ViewChild, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjChartModule } from '@grapecity/wijmo.angular2.chart'; import { DataService } from './app.data'; import * as wjCore from '@grapecity/wijmo'; import * as wjChart from '@grapecity/wijmo.chart'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; @ViewChild('theChart') theChart: wjChart.FlexChart; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); } // sortOnClick(prop: string) { let sd = this.theChart.collectionView.sortDescriptions; // sd.clear(); sd.push(new wjCore.SortDescription(prop, true)) } } // @NgModule({ imports: [WjChartModule, 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 Sorting</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"> <p> ソート: <button id="btnNone" class="btn btn-default" (click)="sortOnClick(null)">なし</button> <button id="btnCountry" class="btn btn-default" (click)="sortOnClick('country')">国</button> <button id="btnSales" class="btn btn-default" (click)="sortOnClick('sales')">売上</button> <button id="btnExpenses" class="btn btn-default" (click)="sortOnClick('expenses')">費用</button> <button id="btnDownloads" class="btn btn-default" (click)="sortOnClick('downloads')">DL数</button> </p> <wj-flex-chart #theChart [itemsSource]="data" bindingX="country"> <wj-flex-chart-series binding="sales" name="売上"></wj-flex-chart-series> <wj-flex-chart-series binding="expenses" name="費用"></wj-flex-chart-series> <wj-flex-chart-series binding="downloads" name="DL数"></wj-flex-chart-series> </wj-flex-chart> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], sales: Math.random() * 10000, expenses: Math.random() * 5000, downloads: Math.round(Math.random() * 20000) }); } // return data; } } body { margin-bottom: 24px; } label { margin-right: 3px; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjCore from "@grapecity/wijmo"; import * as wjChart from "@grapecity/wijmo.react.chart"; import { getData } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData() }; } render() { return <div className="container-fluid"> <div className="form-group"> <p> ソート: <button id="btnNone" className="btn btn-default" onClick={this.sortOnClick.bind(this, null)}>なし</button> <button id="btnCountry" className="btn btn-default" onClick={this.sortOnClick.bind(this, 'country')}>国</button> <button id="btnSales" className="btn btn-default" onClick={this.sortOnClick.bind(this, 'sales')}>売上</button> <button id="btnExpenses" className="btn btn-default" onClick={this.sortOnClick.bind(this, 'expenses')}>費用</button> <button id="btnDownloads" className="btn btn-default" onClick={this.sortOnClick.bind(this, 'downloads')}>DL数</button> </p> <wjChart.FlexChart itemsSource={this.state.data} bindingX="country" initialized={this.initializeChart.bind(this)}> <wjChart.FlexChartSeries binding="sales" name="売上"></wjChart.FlexChartSeries> <wjChart.FlexChartSeries binding="expenses" name="費用"></wjChart.FlexChartSeries> <wjChart.FlexChartSeries binding="downloads" name="DL数"></wjChart.FlexChartSeries> </wjChart.FlexChart> </div> </div>; } initializeChart(flex) { this.theChart = flex; } sortOnClick(prop) { let sd = this.theChart.collectionView.sortDescriptions; // sd.clear(); sd.push(new wjCore.SortDescription(prop, true)); } } 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 OLAP Pivot Chart Overview</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; } label { margin-right: 3px; } export function getData() { let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], sales: Math.random() * 10000, expenses: Math.random() * 5000, downloads: Math.round(Math.random() * 20000) }); } // return data; } <template> <div class="container-fluid"> <div class="form-group"> <p> ソート: <button id="btnNone" class="btn btn-default" v-on:click="sortOnClick(null)">なし</button> <button id="btnCountry" class="btn btn-default" v-on:click="sortOnClick('country')">国</button> <button id="btnSales" class="btn btn-default" v-on:click="sortOnClick('sales')">売上</button> <button id="btnExpenses" class="btn btn-default" v-on:click="sortOnClick('expenses')">費用</button> <button id="btnDownloads" class="btn btn-default" v-on:click="sortOnClick('downloads')">DL数</button> </p> <wj-flex-chart :itemsSource="data" bindingX="country" :initialized="initializeChart"> <wj-flex-chart-series binding="sales" name="売上"></wj-flex-chart-series> <wj-flex-chart-series binding="expenses" name="費用"></wj-flex-chart-series> <wj-flex-chart-series binding="downloads" name="DL数"></wj-flex-chart-series> </wj-flex-chart> </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 { getData } from './data'; import * as wjCore from '@grapecity/wijmo'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData() } }, methods: { initializeChart: function(flex) { this.theChart = flex; }, sortOnClick: function(prop) { let sd = this.theChart.collectionView.sortDescriptions; // sd.clear(); sd.push(new wjCore.SortDescription(prop, true)) } } }) 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 Sorting</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> export function getData() { let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], sales: Math.random() * 10000, expenses: Math.random() * 5000, downloads: Math.round(Math.random() * 20000) }); } // return data; }