Options
  • Show labels
    • Inside the gauge
    • Outside the gauge
  • Show ranges
  • Show border

jQuery Gauge: Gauge Settings

The basic Gauge settings.

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, jqxcheckbox.js, jqxradiobutton.js, jqxexpander.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 () {
    var labels = { visible: true, position: 'inside' };
      
    //Create jqxGauge
    $('#gauge').jqxGauge({
        ranges: [{ startValue: 0, endValue: 90, style: { fill: '#e2e2e2', stroke: '#e2e2e2' }, startDistance: '5%', endDistance: '5%', endWidth: 13, startWidth: 13 },
                 { startValue: 90, endValue: 140, style: { fill: '#f6de54', stroke: '#f6de54' }, startDistance: '5%', endDistance: '5%', endWidth: 13, startWidth: 13 },
                 { startValue: 140, endValue: 180, style: { fill: '#db5016', stroke: '#db5016' }, startDistance: '5%', endDistance: '5%', endWidth: 13, startWidth: 13 },
                 { startValue: 180, endValue: 220, style: { fill: '#d02841', stroke: '#d02841' }, startDistance: '5%', endDistance: '5%', endWidth: 13, startWidth: 13 }
        ],
        cap: { radius: 0.04 },
        caption: { offset: [0, -25], value: 'jQWidgets', position: 'bottom' },
        value: 0,
        style: { stroke: '#ffffff', 'stroke-width': '1px', fill: '#ffffff' },
        animationDuration: 1500,
        colorScheme: 'scheme04',
        labels: labels,
        ticksMinor: { interval: 5, size: '5%' },
        ticksMajor: { interval: 10, size: '10%' }
    });

    //Initialize the Settings panel.
    $('#expander').jqxExpander({ toggleMode: 'none', showArrow: false, width: 200});
    $('#insideRadio').jqxRadioButton({ width: 150, checked: true});
    $('#outsideRadio').jqxRadioButton({ width: 150});
    $('#showLabelsCheckbox').jqxCheckBox({ width: 150, checked: true});
    $('#showRangesCheckbox').jqxCheckBox({ width: 150, checked: true});
    $('#showBorderCheckbox').jqxCheckBox({ width: 150, checked: true});

    //Binding to the widgets's events
    $('#showLabelsCheckbox').on('change', function (e) {
        labels.visible = e.args.checked;
        $('#gauge').jqxGauge('labels', labels);
    });
    $('#showRangesCheckbox').on('change', function (e) {
        $('#gauge').jqxGauge('showRanges', e.args.checked);
    });
    $('#showBorderCheckbox').on('change', function (e) {
        $('#gauge').jqxGauge('border', { visible: e.args.checked });
    });
    $('#outsideRadio').on('change', function (e) {
        if (e.args.checked) {
            labels.position = 'outside';
            $('#gauge').jqxGauge('labels', labels);
        }
    });
    $('#insideRadio').on('change', function (e) {
        if (e.args.checked) {
            labels.position = 'inside';
            $('#gauge').jqxGauge('labels', labels);
        }
    });

    // set gauge's value.
    $('#gauge').jqxGauge('setValue', 220);
});

body.html

<div class="demo-gauge" style="width: 600px;">
    <div id="gauge" style="float: left;"></div>
    <div id="expander" style="float: right;">
        <div>
            Options
        </div>
        <div>
            <ul style="list-style: none; padding: 0px; margin: 10px;">
                <li style="padding: 3px; font-family: Verdana; font-size: 12px;">
                    <div id="showLabelsCheckbox">Show labels</div>
                    <ul style="list-style: none; padding: 0px; margin-top: 10px; margin-left: 20px; font-family: Verdana; font-size: 12px;">
                        <li>
                            <div id="insideRadio">Inside the gauge</div>
                        </li>
                        <li>
                            <div style="margin-top: 5px;" id="outsideRadio">Outside the gauge</div>
                        </li>
                    </ul>
                </li>
                <li style="padding: 3px; font-family: Verdana; font-size: 12px;">
                    <div id="showRangesCheckbox">Show ranges</div>
                </li>
                <li style="padding: 3px; font-family: Verdana; font-size: 12px;">
                    <div id="showBorderCheckbox">Show border</div>
                </li>
            </ul>
        </div>
    </div>
</div>

Learn more

More jQuery Gauge demos