チャート:カスタム軸ラベル

Axisクラスには、軸に沿って特定のラベルの内容と外観をカスタマイズできるitemFormatterプロパティがあります。

指定されている場合、itemFormatter関数は2つのパラメータをとります。

  1. engine: ラベルのレンダリングに使用されるIRenderEngineオブジェクト。
  2. label: ラベルを表し、次のプロパティを持つオブジェクトです。
    • value: ラベルが表す値。
    • text: ラベルのテキストコンテンツ(通常は書式設定された値)。
    • pos: ラベルがレンダリングされる位置(コントロール座標)。
    • cls: ラベル要素に適用されるCSSクラス。
import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjChart from '@grapecity/wijmo.chart'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the chart let theChart = new wjChart.FlexChart('#theChart', { header: '各国のGDP', bindingX: 'country', itemsSource: getData(), series: [{ binding: '2014', name: '2014' }, { binding: '2015', name: '2015' }, { binding: '2016', name: '2016' }], axisY: { itemFormatter: (_, label) => { if (label.val >= 10000000) { label.cls = 'high-value'; } else if (label.val < 5000000) { label.cls = 'low-value'; } return label; } }, }); theChart.palette = getRandomPalette(); } // function getRandomPalette() { 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]]; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Custom Axis Labels/Formatted Labels</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="theChart"></div> </div> </body> </html> // list of country GDP // https://en.wikipedia.org/wiki/List_of_IMF_ranked_countries_by_GDP export function getData() { return [ { country: 'アメリカ', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: '中国', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: '日本', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'ドイツ', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'イギリス', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'フランス', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'インド', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'イタリア', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } .wj-flexchart { height: 300px; } .high-value { fill: darkgreen; font-weight: bold; } .low-value { fill: darkred; } .wj-control { margin-bottom: 6px; } body { margin-bottom: 24pt; } 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 { 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[]; palette: any; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.palette = this.getRandomPalette(); } // itemFormatter(_: any, label: { val: any, text: string, pos: wjCore.Point, cls: string }) { if (label.val >= 10000000) { label.cls = 'high-value'; } else if (label.val < 5000000) { label.cls = 'low-value'; } return label; } // getRandomPalette() { 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]]; } } // @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 Custom Axis Labels/Formatted Labels</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-flex-chart header="各国のGDP" bindingX="country" [itemsSource]="data" [palette]="palette"> <wj-flex-chart-axis wjProperty="axisY" [itemFormatter]="itemFormatter"></wj-flex-chart-axis> <wj-flex-chart-series name="2014" binding="2014"></wj-flex-chart-series> <wj-flex-chart-series name="2015" binding="2015"></wj-flex-chart-series> <wj-flex-chart-series name="2016" binding="2016"></wj-flex-chart-series> </wj-flex-chart> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { return [ { country: 'アメリカ', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: '中国', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: '日本', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'ドイツ', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'イギリス', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'フランス', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'インド', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'イタリア', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } } .wj-flexchart { height: 300px; } .high-value { fill: darkgreen; font-weight: bold; } .low-value { fill: darkred; } .wj-control { margin-bottom: 6px; } body { margin-bottom: 24pt; } 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.react.chart'; import * as wjChart from '@grapecity/wijmo.chart'; import { getData } from './data'; // class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(), palette: this.getRandomPalette() }; } render() { return <div className="container"> <div className="form-group"> <Chart.FlexChart header="各国のGDP" bindingX="country" itemsSource={this.state.data} palette={this.state.palette}> <Chart.FlexChartAxis wjProperty="axisY" itemFormatter={this.itemFormatter.bind(this)}> </Chart.FlexChartAxis> <Chart.FlexChartSeries name="2014" binding="2014"></Chart.FlexChartSeries> <Chart.FlexChartSeries name="2015" binding="2015"></Chart.FlexChartSeries> <Chart.FlexChartSeries name="2016" binding="2016"></Chart.FlexChartSeries> </Chart.FlexChart> </div> </div>; } itemFormatter(_, label) { if (label.val >= 10000000) { label.cls = 'high-value'; } else if (label.val < 5000000) { label.cls = 'low-value'; } return label; } getRandomPalette() { 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]]; } } 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> .wj-flexchart { height: 300px; } body { margin-bottom: 24px; } .high-value { fill: darkgreen; font-weight: bold; } .low-value { fill: darkred; } export function getData() { return [ { country: 'アメリカ', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: '中国', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: '日本', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'ドイツ', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'イギリス', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'フランス', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'インド', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'イタリア', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } <template> <div class="container-fluid"> <div class="form-group"> <wj-flex-chart header="各国のGDP" bindingX="country" :itemsSource="data" :palette="palette"> <wj-flex-chart-axis wjProperty="axisY" :itemFormatter="itemFormatter"></wj-flex-chart-axis> <wj-flex-chart-series name="2014" binding="2014"></wj-flex-chart-series> <wj-flex-chart-series name="2015" binding="2015"></wj-flex-chart-series> <wj-flex-chart-series name="2016" binding="2016"></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 wjChart from '@grapecity/wijmo.chart'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), palette: this.getRandomPalette() } }, methods: { itemFormatter: function(_, label) { if (label.val >= 10000000) { label.cls = 'high-value'; } else if (label.val < 5000000) { label.cls = 'low-value'; } return label; }, 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> .container-fluid .wj-flexchart { height: 300px; } body { margin-bottom: 24px; } .high-value { fill: darkgreen; font-weight: bold; } .low-value { fill: darkred; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Custom Axis Labels/Formatted Labels</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() { return [ { country: 'アメリカ', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: '中国', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: '日本', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'ドイツ', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'イギリス', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'フランス', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'インド', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'イタリア', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; }