Error Bars

The ErrorBar class extends the regular Series class to provide error bars that can be added on top of the regular series data.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as chart from '@grapecity/wijmo.chart'; import * as analytics from '@grapecity/wijmo.chart.analytics'; import * as input from '@grapecity/wijmo.input'; import { getData, getComboData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the chart let theChart = new chart.FlexChart('#theChart', { itemsSource: getData(), bindingX: 'date', axisX: { format: 'MMM yy' }, palette: getRandomPalette() }); // // create an ErrorBar series and add it to the Chart let errorBar = new analytics.ErrorBar({ errorBarStyle: { stroke: 'darkred', strokeWidth: 3 } }); theChart.series.push(errorBar); // // select chart type let chartType = new input.ComboBox('#chartType', { itemsSource: ['Column', 'Bar', 'Scatter', 'Line', 'LineSymbols', 'Area', 'Spline', 'SplineSymbols', 'SplineArea'], textChanged: (s) => { theChart.chartType = s.text; } }); // // select error mode/amount let errorAmount = new input.ComboBox('#errorAmount', { displayMemberPath: 'hdr', textChanged: (sender) => { let value = sender.selectedItem.value; errorBar.value = value; errorBar.binding = value != null ? 'amount' : 'amount,errorPlus,errorMinus'; errorBar.errorAmount = sender.selectedItem.mode; }, itemsSource: getComboData() }); // // randomize the data document.querySelector('#btnRandomize').addEventListener('click', () => { theChart.itemsSource = getData(); }); } // 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 ErrorBar</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 class="form-group"> <label for="chartType">Chart Type: </label> <div id="chartType"></div> </div> <div class="form-group"> <label for="errorAmount">Error: </label> <div id="errorAmount"></div> </div> <div class="form-group"> <label for="btnRandomize">Randomize Data</label> <button id="btnRandomize" class="btn btn-default"> Go </button> </div> <div id="theChart"></div> </div> </body> </html> import * as wijmo from '@grapecity/wijmo'; // // generate some random data export function getData() { let arr = [], date = new Date(); // for (let i = 0; i < 10; i++) { arr.push({ date: date, amount: 20 + 80 * Math.random(), errorPlus: 10 * Math.random(), errorMinus: 10 * Math.random(), }); // date = wijmo.DateTime.addMonths(date, 1); } // return arr; } // export function getComboData() { return [ { hdr: 'Bound Error Values', value: null, mode: 'Custom' }, { hdr: '15%', value: .15, mode: 'Percentage' }, { hdr: '5 units', value: 5, mode: 'FixedValue' }, { hdr: '1.5 Std Dev', value: 1.5, mode: 'StandardDeviation' }, { hdr: 'Standard Error', value: 1, mode: 'StandardError' }, { hdr: 'Plus 5, Minus 10', value: { plus: 5, minus: 10 }, mode: 'Custom' } ]; } .wj-flexchart { height: 250px; margin: 10px 0; } label { width: 150px; text-align: right; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as chart from '@grapecity/wijmo.chart'; // import { Component, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { WjChartModule } from '@grapecity/wijmo.angular2.chart'; import { WjChartAnalyticsModule } from '@grapecity/wijmo.angular2.chart.analytics'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; comboData: any[]; palette: string[]; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.comboData = dataService.getComboData(); this.palette = this._getRandomPalette(); } // randomizeData() { this.data = this.dataService.getData(); } // private _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]]; } } // @NgModule({ imports: [WjInputModule, WjChartModule, WjChartAnalyticsModule, 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 ErrorBar</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="chartType">Chart Type:</label> <wj-combo-box #chartType id="chartType" [itemsSource]="['Column', 'Bar', 'Scatter', 'Line', 'LineSymbols', 'Area', 'Spline', 'SplineSymbols', 'SplineArea']"> </wj-combo-box> </div> <div class="form-group"> <label for="error">Error:</label> <wj-combo-box #error id="error" displayMemberPath="hdr" [itemsSource]="comboData"> </wj-combo-box> </div> <div class="form-group"> <label for="btnRandomize">Randomize Data</label> <button id="btnRandomize" class="btn btn-default" (click)="randomizeData()"> Go </button> </div> <wj-flex-chart [itemsSource]="data" bindingX="date" [chartType]="chartType.selectedValue" [palette]="palette"> <wj-flex-chart-error-bar [binding]="error.selectedValue.value ? 'amount' : 'amount,errorPlus,errorMinus'" [errorBarStyle]="{ stroke: 'darkred', strokeWidth: 3 }" [value]="error.selectedValue.value" [errorAmount]="error.selectedValue.mode"> </wj-flex-chart-error-bar> </wj-flex-chart> </div> import { Injectable } from '@angular/core'; import * as wijmo from '@grapecity/wijmo'; // @Injectable() export class DataService { getData() { let arr = [], date = new Date(); // for (let i = 0; i < 10; i++) { arr.push({ date: date, amount: 20 + 80 * Math.random(), errorPlus: 10 * Math.random(), errorMinus: 10 * Math.random(), }); // date = wijmo.DateTime.addMonths(date, 1); } // return arr; } // getComboData() { return [ { hdr: 'Bound Error Values', value: null, mode: 'Custom' }, { hdr: '15%', value: .15, mode: 'Percentage' }, { hdr: '5 units', value: 5, mode: 'FixedValue' }, { hdr: '1.5 Std Dev', value: 1.5, mode: 'StandardDeviation' }, { hdr: 'Standard Error', value: 1, mode: 'StandardError' }, { hdr: 'Plus 5, Minus 10', value: { plus: 5, minus: 10 }, mode: 'Custom' } ]; } } .wj-flexchart { height: 250px; margin: 10px 0; } label { margin-right: 3px; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <div class="form-group"> <label for="chartType">Chart Type:</label> <wj-combo-box id="chartType" :itemsSource="chartTypes" :selectedIndexChanged="onChartTypeChanged"> </wj-combo-box> </div> <div class="form-group"> <label for="error">Error:</label> <wj-combo-box id="error" displayMemberPath="hdr" :itemsSource="comboData" :selectedIndexChanged="onErrorChanged"> </wj-combo-box> </div> <div class="form-group"> <label for="btnRandomize">Randomize Data</label> <button id="btnRandomize" class="btn btn-default" @click="randomizeData"> Go </button> </div> <wj-flex-chart :itemsSource="data" bindingX="date" :chartType="chartType" :palette="palette"> <wj-flex-chart-error-bar :binding="errorValue ? 'amount' : 'amount,errorPlus,errorMinus'" :errorBarStyle="{ stroke: 'darkred', strokeWidth: 3 }" :value="errorValue" :errorAmount="errorMode"> </wj-flex-chart-error-bar> </wj-flex-chart> </div> </template> <script> import '@grapecity/wijmo.styles/wijmo.css'; import 'bootstrap.css'; import Vue from 'vue'; import * as chart from '@grapecity/wijmo.chart'; import '@grapecity/wijmo.vue2.input'; import '@grapecity/wijmo.vue2.chart'; import '@grapecity/wijmo.vue2.chart.analytics'; import { getData, getComboData } from './data'; // new Vue({ el: '#app', data: { data: getData(), comboData: getComboData(), chartTypes: ['Column', 'Bar', 'Scatter', 'Line', 'LineSymbols', 'Area', 'Spline', 'SplineSymbols', 'SplineArea'], chartType: 'Column', errorValue: null, errorMode: 'Custom', palette: (() => { // Get random palette 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]]; })() }, methods: { onChartTypeChanged(sender) { this.chartType = sender.selectedValue; }, onErrorChanged(sender) { this.errorValue = sender.selectedItem.value; this.errorMode = sender.selectedItem.mode; }, randomizeData() { this.data = getData(); } } }); </script> <style> .container-fluid .wj-flexchart { height: 250px; margin: 10px 0; } label { width: 150px; text-align: right; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart ErrorBar</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> import * as wijmo from '@grapecity/wijmo'; // // generate some random data export function getData() { let arr = [], date = new Date(); // for (let i = 0; i < 10; i++) { arr.push({ date: date, amount: 20 + 80 * Math.random(), errorPlus: 10 * Math.random(), errorMinus: 10 * Math.random(), }); // date = wijmo.DateTime.addMonths(date, 1); } // return arr; } // export function getComboData() { return [ { hdr: 'Bound Error Values', value: null, mode: 'Custom' }, { hdr: '15%', value: .15, mode: 'Percentage' }, { hdr: '5 units', value: 5, mode: 'FixedValue' }, { hdr: '1.5 Std Dev', value: 1.5, mode: 'StandardDeviation' }, { hdr: 'Standard Error', value: 1, mode: 'StandardError' }, { hdr: 'Plus 5, Minus 10', value: { plus: 5, minus: 10 }, mode: 'Custom' } ]; } 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.chart'; import * as wjInput from '@grapecity/wijmo.react.input'; import * as wjChart from '@grapecity/wijmo.react.chart'; import * as wjChartAnalytics from '@grapecity/wijmo.react.chart.analytics'; import { getData, getComboData } from './data'; class App extends React.Component { constructor(props) { super(props); this.randomizeData = () => { this.setState({ data: getData() }); }; this.onChartTypeChanged = (sender) => { this.setState({ chartType: sender.selectedValue }); }; this.onErrorChanged = (sender) => { this.setState({ errorValue: sender.selectedItem.value, errorMode: sender.selectedItem.mode }); }; this.state = { data: getData(), comboData: getComboData(), chartTypes: ['Column', 'Bar', 'Scatter', 'Line', 'LineSymbols', 'Area', 'Spline', 'SplineSymbols', 'SplineArea'], chartType: 'Column', errorValue: null, errorMode: 'Custom', palette: (() => { // Get random palette 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]]; })() }; } render() { return <div className="container-fluid"> <div className="form-group"> <label htmlFor="chartType">Chart Type:</label> <wjInput.ComboBox id="chartType" itemsSource={this.state.chartTypes} selectedIndexChanged={this.onChartTypeChanged}> </wjInput.ComboBox> </div> <div className="form-group"> <label htmlFor="error">Error</label> <wjInput.ComboBox id="error" displayMemberPath="hdr" itemsSource={this.state.comboData} selectedIndexChanged={this.onErrorChanged}> </wjInput.ComboBox> </div> <div className="form-group"> <label htmlFor="btnRandomize">Randomize Data</label> <button id="btnRandomize" className="btn btn-default" onClick={this.randomizeData}> Go </button> </div> <wjChart.FlexChart bindingX="date" itemsSource={this.state.data} palette={this.state.palette} chartType={this.state.chartType}> <wjChartAnalytics.FlexChartErrorBar binding={this.state.errorValue ? 'amount' : 'amount,errorPlus,errorMinus'} name="Sales" groupWidth={0.7} gapWidth={0.2} errorBarStyle={{ stroke: 'darkred', strokeWidth: 3 }} value={this.state.errorValue} errorAmount={this.state.errorMode}> </wjChartAnalytics.FlexChartErrorBar> </wjChart.FlexChart> </div>; } } 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 ErrorBar</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: 250px; margin: 10px 0; } label { margin-right: 3px; } body { margin-bottom: 24pt; } import * as wijmo from '@grapecity/wijmo'; export function getData() { let arr = [], date = new Date(); // for (let i = 0; i < 10; i++) { arr.push({ date: date, amount: 20 + 80 * Math.random(), errorPlus: 10 * Math.random(), errorMinus: 10 * Math.random(), }); // date = wijmo.DateTime.addMonths(date, 1); } // return arr; } // export function getComboData() { return [ { hdr: 'Bound Error Values', value: null, mode: 'Custom' }, { hdr: '15%', value: .15, mode: 'Percentage' }, { hdr: '5 units', value: 5, mode: 'FixedValue' }, { hdr: '1.5 Std Dev', value: 1.5, mode: 'StandardDeviation' }, { hdr: 'Standard Error', value: 1, mode: 'StandardError' }, { hdr: 'Plus 5, Minus 10', value: { plus: 5, minus: 10 }, mode: 'Custom' } ]; }