jQuery Gauge: Gauge with Slider

Dynamically update the Gauge's value.

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.

jqxGauge API used in this demo

Source code

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, jqxdata.js, jqxdraw.js, jqxgauge.js, jqxbuttons.js, jqxslider.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {         
    $('#gauge').jqxGauge({
        ranges: [{ startValue: 0, endValue: 130, style: { fill: '#4cb848', stroke: '#4cb848' }, startDistance: 0, endDistance: 0 },
                 { startValue: 130, endValue: 180, style: { fill: '#fad00b', stroke: '#fad00b' }, startDistance: 0, endDistance: 0 },
                 { startValue: 180, endValue: 220, style: { fill: '#e53d37', stroke: '#e53d37' }, startDistance: 0, endDistance: 0}],
        cap: { size: '5%', style: { fill: '#2e79bb', stroke: '#2e79bb'} },
        border: { style: { fill: '#8e9495', stroke: '#7b8384', 'stroke-width': 1 } },
        ticksMinor: { interval: 5, size: '5%' },
        ticksMajor: { interval: 20, size: '10%' },       
        labels: { position: 'outside', interval: 20 },
        pointer: { style: { fill: '#2e79bb' }, width: 5 },
        animationDuration: 1500
    });
    $('#slider').jqxSlider({ min: 0, max: 220, mode: 'fixed', ticksFrequency: 20, width: 180, value: 120,  showButtons: false });

    $('#slider').mousedown(function () {
        $('#gauge').jqxGauge('value', $('#slider').jqxSlider('value'));
    });
    $('#slider').on('slideEnd', function (e) {
        $('#gauge').jqxGauge('value', e.args.value);
    });
    $('#slider').on('mousewheel', function () {
        $('#gauge').jqxGauge('value', $('#slider').jqxSlider('value'));
    });
    $('#gauge').jqxGauge('value', 120);
});

body.html

<div class="demo-gauge" style="position: relative; height: 380px;">
    <div id="gauge" style="position: absolute; top: 0px; left: 0px;">
    </div>
    <div id="slider" style="position: absolute; top: 250px; left: 93px">
    </div>
</div>

Learn more

More jQuery Gauge demos