DevExtreme v24.2 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

JavaScript/jQuery Gauges - Variable Number of Subvalue Indicators

This demo shows how to use the API of the LinearGauge to change its value and subvalue indicators at runtime. To get and set values of the indicators, the value and subvalues methods are utilized.

Backend API
$(() => { const gauge = $('#gauge').dxLinearGauge({ scale: { startValue: 0, endValue: 10, tickInterval: 2, label: { customizeText(arg) { return `${arg.valueText} kW`; }, }, }, tooltip: { enabled: true, customizeTooltip(arg) { let result = `${arg.valueText} kW`; if (arg.index >= 0) { result = `Secondary ${arg.index + 1}: ${result}`; } else { result = `Primary: ${result}`; } return { text: result, }; }, }, export: { enabled: true, }, title: { text: 'Power of Air Conditioners in Store Departments (kW)', font: { size: 28 }, }, value: dataSource[0].primary, subvalues: dataSource[0].secondary, }).dxLinearGauge('instance'); $('#selectbox').dxSelectBox({ dataSource, inputAttr: { 'aria-label': 'Department' }, displayExpr: 'name', onValueChanged(data) { gauge.value(data.value.primary); gauge.subvalues(data.value.secondary); }, value: dataSource[0], width: 200, }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <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=5.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.2.3/css/dx.light.css" /> <script src="js/dx.all.js"></script> <script src="data.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="gauge-demo"> <div id="gauge"></div> <div id="selectbox"></div> </div> </div> </body> </html>
#gauge-demo { height: 440px; width: 100%; } #gauge { height: 400px; }
const dataSource = [{ name: 'Meat', primary: 8, secondary: [7, 3], }, { name: 'Fish', primary: 7, secondary: [7, 5, 1], }, { name: 'Grocery', primary: 5, secondary: [1, 3], }, { name: 'Greengrocery', primary: 3, secondary: [1], }, { name: 'Stationery', primary: 2, secondary: [], }];