Your search did not match any results.
Bar Gauge

Variable Number of Bars

Documentation

This demo shows how to use the API of the BarGauge to change the number of indicated values at runtime. For this purpose, an array of new values is passed as the parameter of the value method.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import { BarGauge, Label } from 'devextreme-react/bar-gauge'; import { products } from './data.js'; import { CheckBox } from 'devextreme-react/check-box'; const format = { type: 'fixedPoint', precision: 0 }; class App extends React.Component { constructor(props) { super(props); this.state = { productsActivity: products.map(p => p.active), values: products.map(p=>p.count) }; this.getValueChangedHandler = (productIndex) => { return (e) => { const productsActivity = this.state.productsActivity.slice(); productsActivity[productIndex] = e.value; this.setState({ productsActivity, values: products.map((p, i) => productsActivity[i] ? p.count : null).filter(c => c !== null) }); }; }; } render() { return ( <div> <div className="long-title"> <h3>Sampling by Goods</h3> </div> <div id="gauge-demo"> <BarGauge id="gauge" startValue={0} endValue={50} values={this.state.values} > <Label format={format} /> </BarGauge> <div id="panel"> {this.state.productsActivity.map((p, i) => <CheckBox key={i} text={products[i].name} value={p} onValueChanged={this.getValueChangedHandler(i)} ></CheckBox>)} </div> </div> </div> ); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.light.css" /> <link rel="stylesheet" type ="text/css" href="styles.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
#gauge-demo { height: 440px; width: 100%; } #gauge { width: 80%; height: 100%; margin-top: 20px; float: left; } #panel { width: 150px; text-align: left; margin-top: 20px; float: left; } .dx-checkbox { margin-bottom: 10px; display: block; } .long-title h3 { font-weight: 200; font-size: 28px; text-align: center; margin-bottom: 20px; }
export const products = [{ name: 'Hummers', count: 41, active: true }, { name: 'Shovers', count: 32, active: true }, { name: 'Ladders', count: 13, active: true }, { name: 'Watering cans', count: 48, active: true }, { name: 'Screwdrivers', count: 24, active: true }, { name: 'Nail pullers', count: 8, active: true }, { name: 'Drills', count: 19, active: true }];
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16/umd/react.development.js', 'react-dom': 'npm:react-dom@16/umd/react-dom.development.js', 'prop-types': 'npm:prop-types/prop-types.js', 'devextreme': 'npm:devextreme@19.2', 'devextreme-react': 'npm:devextreme-react@19.2', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });