カスタムツールチップ

サンプルは、画像を表示するカスタマイズされたツールチップを紹介します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as chart from '@grapecity/wijmo.chart'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let barchart = new chart.FlexChart('#chart', { header: '各国のGDP', legend: { position: chart.Position.Bottom }, bindingX: 'title', series: [{ binding: 'sales', name: '売上' }, { binding: 'downloads', name: 'DL数' }], tooltip: { content: (hti) => { let item = hti.item; return `<b>国: </b>${item.title} <img src="resources/${item.country}.png" /></br>DL数: ${item.downloads}</br>売上: ${item.sales}`; } }, itemsSource: getData() }); barchart.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 Custom Tooltips</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> //generate random data. export function getData() { let data = []; let titles = { germany: 'ドイツ', us: 'アメリカ', italy: 'イタリア', uk: 'イギリス', japan: '日本', canada: 'カナダ', greece: 'ギリシャ' }; 'germany,us,italy,uk,japan,canada,greece'.split(',').forEach(country => { data.push({ country: country, title: titles[country], sales: Math.round(Math.random() * 10000), downloads: Math.round(Math.random() * 50000) }); }); return data; } body { margin-bottom: 24px; } 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 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(); } // tooltipContent(hti: wjChart.HitTestInfo) { let item = hti.item; return `<b>国: </b>${item.title} <img src="resources/${item.country}.png" /></br>DL数: ${item.downloads}</br>売上: ${item.sales}`; } // 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 Tooltips</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 bindingX="title" [itemsSource]="data" [palette]="palette" [tooltipContent]="tooltipContent"> <wj-flex-chart-legend position="Bottom"></wj-flex-chart-legend> <wj-flex-chart-series binding="sales" 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 data: any[] = []; let titles = { germany: 'ドイツ', us: 'アメリカ', italy: 'イタリア', uk: 'イギリス', japan: '日本', canada: 'カナダ', greece: 'ギリシャ' }; 'germany,us,italy,uk,japan,canada,greece'.split(',').forEach(country => { data.push({ country: country, title: titles[country], sales: Math.round(Math.random() * 10000), downloads: Math.round(Math.random() * 50000) }); }); return data; } } body { margin-bottom: 24px; } label { margin-right: 3px; } 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(), tooltipContent: function (hti) { let item = hti.item; return `<b>国: </b>${item.title} <img src="resources/${item.country}.png" /></br>DL数: ${item.downloads}</br>売上: ${item.sales}`; } }; } // render() { return <div className="container"> <div className="form-group"> <Chart.FlexChart bindingX="title" itemsSource={this.state.data} palette={this.state.palette}> <Chart.FlexChartLegend position="Bottom"></Chart.FlexChartLegend> <Chart.FlexChartSeries name="売上" binding="sales" tooltipContent={this.state.tooltipContent}></Chart.FlexChartSeries> <Chart.FlexChartSeries name="DL数" binding="downloads" tooltipContent={this.state.tooltipContent}></Chart.FlexChartSeries> </Chart.FlexChart> </div> </div>; } // 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 FlexChart Custom Tooltips</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 data = []; let titles = { germany: 'ドイツ', us: 'アメリカ', italy: 'イタリア', uk: 'イギリス', japan: '日本', canada: 'カナダ', greece: 'ギリシャ' }; 'germany,us,italy,uk,japan,canada,greece'.split(',').forEach(country => { data.push({ country: country, title: titles[country], sales: Math.round(Math.random() * 10000), downloads: Math.round(Math.random() * 50000) }); }); return data; } <template> <div class="container-fluid"> <div class="form-group"> <wj-flex-chart bindingX="title" :itemsSource="data" :palette="palette" :tooltipContent="tooltipContent"> <wj-flex-chart-legend position="Bottom"></wj-flex-chart-legend> <wj-flex-chart-series binding="sales" 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 wjChart from '@grapecity/wijmo.chart'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), palette: this.getRandomPalette() } }, methods: { tooltipContent: function(hti) { let item = hti.item; return `<b>国: </b>${item.title} <img src="resources/${item.country}.png" /></br>DL数: ${item.downloads}</br>売上: ${item.sales}`; }, 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 Custom Tooltips</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 data = []; let titles = { germany: 'ドイツ', us: 'アメリカ', italy: 'イタリア', uk: 'イギリス', japan: '日本', canada: 'カナダ', greece: 'ギリシャ' }; 'germany,us,italy,uk,japan,canada,greece'.split(',').forEach(country => { data.push({ country: country, title: titles[country], sales: Math.round(Math.random() * 10000), downloads: Math.round(Math.random() * 50000) }); }); return data; }