Series Picker

You can easily implement a series-picker UI using the chart's series property, a ListBox control, and Wijmo's showPopup and hidePopup methods.

For example, the chart below starts with an auto-generated set of series. Click the gear icon at the top-left corner to show a ListBox where you can select the series you want to display.

Note that you can achieve a similar result by setting the chart's legendToggle property to true. Once you do that, the legend itself acts as a series picker: clicking any series name in the legend toggles its visibility.

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 * as wjInput from '@grapecity/wijmo.input'; 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' }); theChart.palette = getRandomPalette(); // // auto-generate series let item = theChart.itemsSource[0]; for (let k in item) { if (wjCore.isNumber(item[k])) { let series = new wjChart.Series(); series.binding = k; series.name = wjCore.toHeaderCase(k); series['visible'] = true; // add 'visible' property for binding theChart.series.push(series); } } // // create the series picker let theSeriesPicker = new wjInput.ListBox('#theSeriesPicker', { itemsSource: theChart.series, checkedMemberPath: 'visible', displayMemberPath: 'name', lostFocus: () => { wjCore.hidePopup(theSeriesPicker.hostElement); }, checkedItemsChanged: (s) => { // map extra 'visible' property to 'Series.visibility' values theChart.series.forEach((series) => { series.visibility = s.checkedItems.indexOf(series) > -1 ? wjChart.SeriesVisibility.Visible : wjChart.SeriesVisibility.Hidden; }); } }); // document.querySelector('#pickerButton').addEventListener('click', e => { wjCore.showPopup(theSeriesPicker.hostElement, e.target, false, true, false); theSeriesPicker.focus(); e.preventDefault(); }); } // 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 Series Picker</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 style="position:relative"> <div id="theChart"></div> <div id="pickerButton"> <span class="column-picker-icon glyphicon glyphicon-cog"></span> </div> </div> <div style="display:none"> <div id="theSeriesPicker" class="series-picker"></div> </div> </div> </body> </html> // generate some random data export function getData() { let countries = 'US,Canada,Mexico,Japan,Korea,China,Germany,France,UK,Italy,Greece'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], leads: Math.random() * 100000, qualified: Math.random() * 50000, analysis: Math.random() * 5000, quotes: Math.random() * 4000, negotiations: Math.random() * 1000, sales: Math.random() * 800 }); } // return data; } .wj-flexchart { height: 300px; margin: 10px 0; } .series-picker { columns: 2; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } #pickerButton { cursor: pointer; color: #FF8754; padding: 6px; position: absolute; left: 0; top: 0 } body { margin-bottom: 20px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, ViewChild, enableProdMode, NgModule, AfterViewInit } 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 wjCore from '@grapecity/wijmo'; 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[]; palette: any; @ViewChild('theChart') theChart: wjChart.FlexChart; @ViewChild('theSeriesPicker') theSeriesPicker: wjInput.ListBox; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.palette = this.getRandomPalette(); } // ngAfterViewInit() { // auto-generate series let item = this.data[0]; for (let k in item) { if (wjCore.isNumber(item[k])) { let series = new wjChart.Series(); series.binding = k; series.name = wjCore.toHeaderCase(k); series['visible'] = true; // add 'visible' property for binding this.theChart.series.push(series); } } } // 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]]; } // pickerClick(e: Event) { wjCore.showPopup(this.theSeriesPicker.hostElement, e.target, false, true, false); this.theSeriesPicker.focus(); e.preventDefault(); } // lostFocus() { wjCore.hidePopup(this.theSeriesPicker.hostElement); } // checkedItemsChanged(s: wjInput.ListBox) { // map extra 'visible' property to 'Series.visibility' values this.theChart.series.forEach((series: wjChart.Series) => { series.visibility = s.checkedItems.indexOf(series) > -1 ? wjChart.SeriesVisibility.Visible : wjChart.SeriesVisibility.Hidden; }); } } // @NgModule({ imports: [FormsModule, WjInputModule, 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 Series Picker</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"> <div style="position:relative"> <wj-flex-chart #theChart [itemsSource]="data" bindingX="country" [palette]="palette"></wj-flex-chart> <div id="pickerButton" (click)="pickerClick($event)"> <span class="column-picker-icon glyphicon glyphicon-cog"></span> </div> </div> <div style="display:none"> <wj-list-box #theSeriesPicker [itemsSource]="this.theChart.series" checkedMemberPath="visible" displayMemberPath="name" (lostFocus)="lostFocus()" (checkedItemsChanged)="checkedItemsChanged(theSeriesPicker)"></wj-list-box> </div> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { let countries = 'US,Canada,Mexico,Japan,Korea,China,Germany,France,UK,Italy,Greece'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], leads: Math.random() * 100000, qualified: Math.random() * 50000, analysis: Math.random() * 5000, quotes: Math.random() * 4000, negotiations: Math.random() * 1000, sales: Math.random() * 800 }); } // return data; } } .wj-flexchart { height: 300px; margin: 10px 0; } .series-picker { columns: 2; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } #pickerButton { cursor: pointer; color: #FF8754; padding: 6px; position: absolute; left: 0; top: 0 } body { margin-bottom: 20px; } <template> <div class="container-fluid"> <div class="form-group"> <div style="position:relative"> <wj-flex-chart :itemsSource="data" bindingX="country" :palette="palette" :initialized="initializeChart"></wj-flex-chart> <div id="pickerButton" v-on:click="pickerClick"> <span class="column-picker-icon glyphicon glyphicon-cog"></span> </div> </div> <div style="display:none"> <wj-list-box :initialized="initializeLB" :itemsSource="lbData" checkedMemberPath="visible" displayMemberPath="name" :lostFocus="lostFocus" :checkedItemsChanged="checkedItemsChanged"></wj-list-box> </div> </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 } from './data'; import * as wjCore from '@grapecity/wijmo'; import * as wjChart from '@grapecity/wijmo.chart'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), palette: this.getRandomPalette(), lbData: null } }, methods: { initializeChart: function(flex) { this.theChart = flex; // auto-generate series let item = this.data[0]; for (let k in item) { if (wjCore.isNumber(item[k])) { let series = new wjChart.Series(); series.binding = k; series.name = wjCore.toHeaderCase(k); series['visible'] = true; // add 'visible' property for binding this.theChart.series.push(series); } } this.lbData = flex.series; }, initializeLB: function(flex) { this.theSeriesPicker = flex; }, 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]]; }, pickerClick: function(e) { wjCore.showPopup(this.theSeriesPicker.hostElement, e.target, false, true, false); this.theSeriesPicker.focus(); e.preventDefault(); }, lostFocus: function() { wjCore.hidePopup(this.theSeriesPicker.hostElement); }, checkedItemsChanged: function(s) { // map extra 'visible' property to 'Series.visibility' values this.theChart.series.forEach(series => { series.visibility = s.checkedItems.indexOf(series) > -1 ? wjChart.SeriesVisibility.Visible : wjChart.SeriesVisibility.Hidden; }); } } }) new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> body { margin-bottom: 24px; } label { margin-right: 3px; } .series-picker { columns: 2; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } #pickerButton { cursor: pointer; color: #FF8754; padding: 6px; position: absolute; left: 0; top: 0 } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Series Picker</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 = 'US,Canada,Mexico,Japan,Korea,China,Germany,France,UK,Italy,Greece'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], leads: Math.random() * 100000, qualified: Math.random() * 50000, analysis: Math.random() * 5000, quotes: Math.random() * 4000, negotiations: Math.random() * 1000, sales: Math.random() * 800 }); } // return data; } 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 * as wjInput from "@grapecity/wijmo.react.input"; import * as wjcChart from "@grapecity/wijmo.chart"; import { getData } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(), palette: this.getRandomPalette(), lbData: null }; } render() { return <div className="container-fluid"> <div className="form-group"> <div style={{ position: 'relative' }}> <wjChart.FlexChart itemsSource={this.state.data} bindingX="country" palette={this.state.palette} initialized={this.initializeChart.bind(this)}></wjChart.FlexChart> <div id="pickerButton" onClick={this.pickerClick.bind(this)}> <span className="column-picker-icon glyphicon glyphicon-cog"></span> </div> </div> <div style={{ display: 'none' }}> <wjInput.ListBox initialized={this.initializeLB.bind(this)} itemsSource={this.state.lbData} checkedMemberPath="visible" displayMemberPath="name" lostFocus={this.lostFocus.bind(this)} checkedItemsChanged={this.checkedItemsChanged.bind(this)}></wjInput.ListBox> </div> </div> </div>; } initializeChart(flex) { this.theChart = flex; // auto-generate series let item = this.state.data[0]; for (let k in item) { if (wjCore.isNumber(item[k])) { let series = new wjcChart.Series(); series.binding = k; series.name = wjCore.toHeaderCase(k); series['visible'] = true; // add 'visible' property for binding this.theChart.series.push(series); } } this.setState({ lbData: flex.series }); } initializeLB(flex) { this.theSeriesPicker = flex; } getRandomPalette() { let palettes = Object.getOwnPropertyNames(wjcChart.Palettes) .filter(prop => typeof wjcChart.Palettes[prop] === "object" && prop !== 'prototype'); let rand = Math.floor(Math.random() * palettes.length); // return wjcChart.Palettes[palettes[rand]]; } pickerClick(e) { wjCore.showPopup(this.theSeriesPicker.hostElement, e.target, false, true, false); this.theSeriesPicker.focus(); e.preventDefault(); } lostFocus() { wjCore.hidePopup(this.theSeriesPicker.hostElement); } checkedItemsChanged(s) { // map extra 'visible' property to 'Series.visibility' values this.theChart.series.forEach(series => { series.visibility = s.checkedItems.indexOf(series) > -1 ? wjcChart.SeriesVisibility.Visible : wjcChart.SeriesVisibility.Hidden; }); } } 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; } .series-picker { columns: 2; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } #pickerButton { cursor: pointer; color: #FF8754; padding: 6px; position: absolute; left: 0; top: 0 } export function getData() { let countries = 'US,Canada,Mexico,Japan,Korea,China,Germany,France,UK,Italy,Greece'.split(','), data = []; // for (let i = 0; i < countries.length; i++) { data.push({ country: countries[i], leads: Math.random() * 100000, qualified: Math.random() * 50000, analysis: Math.random() * 5000, quotes: Math.random() * 4000, negotiations: Math.random() * 1000, sales: Math.random() * 800 }); } // return data; }