jqxGauge displays an indicator within a range of values. Gauges can be used in a table or matrix to show the relative value of a field in a range of values in the data region, for example, as a KPI.
A live JavaScript/jQuery example of jqxGauge, the jQWidgets Gauge component, with its complete source code below. It is one of 6 jqxGauge demos for jQuery.
animationDuration property – Sets or gets jqxGauge's animation duration [ms].colorScheme property – Sets the gauge's color palette.height property – Sets or gets the gauge's height.labels property – Sets or gets the gauge's properties for it's labels.max property – Sets or gets jqxGauge's max value.pointer property – Sets or gets the gauge's properties for it's pointer.ranges property – This property is array of objects.ticksMajor property – Sets or gets the gauge's properties for it's major ticks.ticksMinor property – Sets or gets the gauge's properties for it's minor ticks.value property – Sets or gets gauge's value.width property – Sets or gets the gauge's width.valueChanging event – The event is is triggered when the gauge's value is changing.To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGauge shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdraw.js, jqxgauge.js.
$(document).ready(function () {
$('#gaugeContainer').jqxGauge({
ranges: [{ startValue: 0, endValue: 55, style: { fill: '#4bb648', stroke: '#4bb648' }, endWidth: 5, startWidth: 1 },
{ startValue: 55, endValue: 110, style: { fill: '#fbd109', stroke: '#fbd109' }, endWidth: 10, startWidth: 5 },
{ startValue: 110, endValue: 165, style: { fill: '#ff8000', stroke: '#ff8000' }, endWidth: 13, startWidth: 10 },
{ startValue: 165, endValue: 220, style: { fill: '#e02629', stroke: '#e02629' }, endWidth: 16, startWidth: 13 }],
ticksMinor: { interval: 5, size: '5%' },
ticksMajor: { interval: 10, size: '9%' },
value: 0,
colorScheme: 'scheme05',
animationDuration: 1200
});
$('#gaugeContainer').on('valueChanging', function (e) {
$('#gaugeValue').text(Math.round(e.args.value) + ' kph');
});
$('#gaugeContainer').jqxGauge('value', 140);
$('#linearGauge').jqxLinearGauge({
orientation: 'vertical',
width: 100,
height: 350,
ticksMajor: { size: '10%', interval: 10 },
ticksMinor: { size: '5%', interval: 2.5, style: { 'stroke-width': 1, stroke: '#aaaaaa'} },
max: 60,
pointer: { size: '5%' },
colorScheme: 'scheme05',
labels: { interval: 20, formatValue: function (value, position) {
if (position === 'far') {
value = (9 / 5) * value + 32;
if (value === -76) {
return '°F';
}
return value + '°';
}
if (value === -60) {
return '°C';
}
return value + '°';
}
},
ranges: [
{ startValue: -10, endValue: 10, style: { fill: '#FFF157', stroke: '#FFF157'} },
{ startValue: 10, endValue: 35, style: { fill: '#FFA200', stroke: '#FFA200'} },
{ startValue: 35, endValue: 60, style: { fill: '#FF4800', stroke: '#FF4800'}}],
animationDuration: 1500
});
$('#linearGauge').jqxLinearGauge('value', 40);
});
<div id="demoWidget" style="position: relative;">
<div style="float: left;" id="gaugeContainer"></div>
<div id="gaugeValue" style="position: absolute; top: 235px; left: 132px; font-family: Sans-Serif; text-align: center; font-size: 17px; width: 70px;"></div>
<div style="margin-left: 60px; float: left;" id="linearGauge"></div>
</div>