数据标签

dataLabels 属性允许您在图表上的每个数据点旁边显示标签。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjChart from '@grapecity/wijmo.chart'; import * as wjInput from '@grapecity/wijmo.input'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create a chart let downloadsOnly = false, theChart = new wjChart.FlexChart('#theChart', { itemsSource: getData(), bindingX: 'country', tooltip: { content: '' }, header: 'Country GDP', series: [{ binding: '2014', name: '2014' }, { binding: '2015', name: '2015' }, { binding: '2016', name: '2016' }], dataLabel: { content: '{value:n0,,}T', position: 'Top', rendering: (_, e) => { if (downloadsOnly && e.hitTestInfo.series.binding != '2016') { e.cancel = true; // labels only for the "downloads" series } } }, options: { groupWidth: '90%' } }); theChart.palette = getRandomPalette(); // // customize the data labels let labelPosition = new wjInput.ComboBox('#labelPosition', { itemsSource: 'None,Left,Top,Right,Bottom,Center'.split(','), textChanged: (s) => { theChart.dataLabel.position = s.text; }, text: 'Top' }); // document.querySelector('#linesAndBorders').addEventListener('click', e => { let dl = theChart.dataLabel; dl.connectingLine = dl.border = e.target.checked; }); // document.querySelector('#downloadsOnly').addEventListener('click', e => { downloadsOnly = e.target.checked; theChart.invalidate(); }); } // 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 Data 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"> <label for="labelPosition">Label Position: </label> <div id="labelPosition"></div><br /> <label for="linesAndBorders">Lines/Borders: </label> <input id="linesAndBorders" type="checkbox"><br /> <label for="downloadsOnly">2016 Only: </label> <input id="downloadsOnly" type="checkbox"> <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: 'United States', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: 'China', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: 'Japan', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'Germany', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'United Kingdom', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'France', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'India', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'Italy', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } .wj-flexgrid { height: 150px; margin-top:10px; } .wj-flexchart { height: 300px; } .wj-data-label { font-size: 75%; opacity: .9; } label { width: 150px; text-align: right; } .wj-control { margin-bottom: 3px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, enableProdMode, AfterViewInit, NgModule, ViewChild } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { WjChartModule } from '@grapecity/wijmo.angular2.chart'; import { DataService } from './app.data'; import * as wjInput from '@grapecity/wijmo.input'; import * as wjChart from '@grapecity/wijmo.chart'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements AfterViewInit { data: any[]; comboData: any[]; palette: any; downloadsOnly: boolean; @ViewChild('theChart') theChart: wjChart.FlexChart; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.comboData = dataService.getComboData(); this.palette = this.getRandomPalette(); this.downloadsOnly = false; } // ngAfterViewInit() { this.theChart.dataLabel.rendering.addHandler(function(_: any, e: wjChart.DataLabelRenderEventArgs) { if (this.downloadsOnly && e.hitTestInfo.series.binding != '2016') { e.cancel = true; // labels only for the "downloads" series } }, this); } // textChanged(s: wjInput.ComboBox) { this.theChart.dataLabel.position = <any>s.text; } // 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]]; } // lbClick(cb: HTMLInputElement) { let dl = this.theChart.dataLabel; dl.connectingLine = dl.border = cb.checked; } // doClick(cb: HTMLInputElement) { this.theChart.invalidate(); } } // @NgModule({ imports: [WjInputModule, WjChartModule, FormsModule, 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 Data 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"> <label for="labelPosition">Label Position: </label> <wj-combo-box #cb [itemsSource]="comboData" (textChanged)="textChanged(cb)" text="Top"></wj-combo-box><br /> <label for="linesAndBorders">Lines/Borders: </label> <input #lb id="linesAndBorders" type="checkbox" (click)="lbClick(lb)" /><br /> <label for="downloadsOnly">2016 Only: </label> <input #do id="downloadsOnly" type="checkbox" [(ngModel)]="downloadsOnly" (click)="doClick(do)" /> </div> <div class="form-group"> <wj-flex-chart #theChart [itemsSource]="data" bindingX="country" tooltipContent="" header="Country GDP" [palette]="palette" [options]="{ groupWidth : '90%' }"> <wj-flex-chart-series binding="2014" name="2014"></wj-flex-chart-series> <wj-flex-chart-series binding="2015" name="2015"></wj-flex-chart-series> <wj-flex-chart-series binding="2016" name="2016"></wj-flex-chart-series> <wj-flex-chart-data-label content="{value:n0,,}T" position="Top"></wj-flex-chart-data-label> </wj-flex-chart> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { // https://en.wikipedia.org/wiki/List_of_IMF_ranked_countries_by_GDP getData() { return [ { country: 'United States', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: 'China', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: 'Japan', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'Germany', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'United Kingdom', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'France', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'India', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'Italy', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } // getComboData() { return 'None,Left,Top,Right,Bottom,Center'.split(','); } } .wj-flexgrid { height: 150px; margin-top:10px; } .wj-flexchart { height: 300px; } .wj-data-label { font-size: 75%; opacity: .9; } label { width: 150px; text-align: right; } .wj-control { margin-bottom: 3px; } <template> <div class="container-fluid"> <div class="form-group"> <label for="labelPosition">Label Position: </label> <wj-combo-box :itemsSource="comboData" :textChanged="textChanged" text="Top"></wj-combo-box><br /> <label for="linesAndBorders">Lines/Borders: </label> <input id="linesAndBorders" type="checkbox" v-on:click="lbClick" /><br /> <label for="downloadsOnly">2016 Only: </label> <input id="downloadsOnly" type="checkbox" v-model="downloadsOnly" v-on:click="doClick" /> </div> <div class="form-group"> <wj-flex-chart :itemsSource="data" bindingX="country" tooltipContent="" header="Country GDP" :palette="palette" :initialized="chartInitialized"> <wj-flex-chart-series binding="2014" name="2014"></wj-flex-chart-series> <wj-flex-chart-series binding="2015" name="2015"></wj-flex-chart-series> <wj-flex-chart-series binding="2016" name="2016"></wj-flex-chart-series> <wj-flex-chart-data-label content="{value:n0,,}T" position="Top"></wj-flex-chart-data-label> </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.input'; import '@grapecity/wijmo.vue2.chart'; import { getData, getComboData } from './data'; import * as wjChart from '@grapecity/wijmo.chart'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), comboData: getComboData(), palette: this.getRandomPalette(), downloadsOnly: false } }, methods: { chartInitialized(flex) { this.theChart = flex; flex.dataLabel.rendering.addHandler(function(_, e) { if (this.downloadsOnly && e.hitTestInfo.series.binding != '2016') { e.cancel = true; // labels only for the "downloads" series } }, this); }, textChanged(s) { this.theChart.dataLabel.position = s.text; }, 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]]; }, lbClick(cb) { let dl = this.theChart.dataLabel; dl.connectingLine = dl.border = cb.target.checked; }, doClick() { this.theChart.invalidate(); } } }) 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 Data 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: 'United States', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: 'China', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: 'Japan', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'Germany', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'United Kingdom', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'France', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'India', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'Italy', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } export function getComboData() { return 'None,Left,Top,Right,Bottom,Center'.split(','); } 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 Input from '@grapecity/wijmo.react.input'; import * as wjChart from '@grapecity/wijmo.chart'; import { getData, getComboData } from './data'; // class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(), comboData: getComboData(), palette: this.getRandomPalette(), downloadsOnly: false, showLinesAndBorders: false }; } render() { return <div className="container"> <div className="form-group"> <label>Label Position: <Input.ComboBox itemsSource={this.state.comboData} textChanged={this.textChanged.bind(this)} text="Top"> </Input.ComboBox> </label> <label>Lines/Borders: <input id="checkBoxLinesAndBorders" type="checkbox" checked={this.state.showLinesAndBorders} onChange={this.showLinesAndBordersChanged.bind(this)}/><br /> </label> <label>2016 Only: <input id="checkBoxDownloadsOnly" type="checkbox" checked={this.state.downloadsOnly} onChange={this.downloadsOnlyChanged.bind(this)}/><br /> </label> <div className="form-group"> <Chart.FlexChart bindingX="country" itemsSource={this.state.data} tooltipContent="" header="Country GDP" initialized={this.chartInitialized.bind(this)} palette={this.state.palette}> <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.FlexChartDataLabel content="{value:n0,,}T" position="Top"></Chart.FlexChartDataLabel> </Chart.FlexChart> </div> </div> </div>; } chartInitialized(flex) { this.theChart = flex; flex.dataLabel.rendering.addHandler(function (_, e) { if (this.state.downloadsOnly && e.hitTestInfo.series.binding != '2016') { e.cancel = true; // labels only for the "downloads" series } }, this); } textChanged(s) { if (this.theChart) { this.theChart.dataLabel.position = s.text; } } showLinesAndBordersChanged() { if (this.theChart) { let dl = this.theChart.dataLabel; dl.connectingLine = dl.border = !this.state.showLinesAndBorders; } this.setState({ showLinesAndBorders: !this.state.showLinesAndBorders }); } downloadsOnlyChanged() { if (this.theChart) { this.setState({ downloadsOnly: !this.state.downloadsOnly }); this.theChart.invalidate(); } } 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> body { margin-bottom: 24px; } label { margin-right: 3px; padding: 10px; } input { vertical-align: top; margin-left: 5px !important; } export function getData() { return [ { country: 'United States', '2014': 17348075, '2015': 18036650, '2016': 18624450 }, { country: 'China', '2014': 10356508, '2015': 11181556, '2016': 11232110 }, { country: 'Japan', '2014': 4602367, '2015': 4124211, '2016': 4936540 }, { country: 'Germany', '2014': 3874437, '2015': 3365293, '2016': 3479230 }, { country: 'United Kingdom', '2014': 2950039, '2015': 2858482, '2016': 2629190 }, { country: 'France', '2014': 2833687, '2015': 2420163, '2016': 2466470 }, { country: 'India', '2014': 2051228, '2015': 2073002, '2016': 2263790 }, { country: 'Italy', '2014': 2147744, '2015': 1815759, '2016': 1850740 } ]; } export function getComboData() { return 'None,Left,Top,Right,Bottom,Center'.split(','); }