Red
Green
Blue

jQuery BarGauge: Update Values

Proportion between Red, Green and Blue in custom color, represented in jqxBarGauge.

A live JavaScript/jQuery example of jqxBarGauge, the jQWidgets BarGauge component, with its complete source code below. It is one of 8 jqxBarGauge demos for jQuery.

jqxBarGauge 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 $.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdraw.js, jqxbargauge.js, jqxcolorpicker.js, jqxradiobutton.js, jqxdropdownbutton.js, jqxslider.js, jqxscrollview.js, jqxbuttons.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 colorArray = [];
    var rgbArray = [187, 255, 170];
    var disabled = false;
    var isRendered = false;
    var isClosed = false;

    $('#barGauge').jqxBarGauge({
        width: getWidth('BarGauge'),
        height: getHeight('BarGauge'),
        values: rgbArray,
        max: 255,
        relativeInnerRadius: 0.5,
        startAngle: 0,
        endAngle: 90,
        colorScheme: 'rgb',
        customColorScheme: {
            name: 'rgb',
            colors: ['#307DD7', '#89A54E', '#AA4643']
        },
        title: {
            text: 'jqxBarGauge',
            font: {
                size: 40
            },
            verticalAlignment: 'top',
            margin: 0,
            subtitle: {
                text: '( visualization of "RGB" color proportions )',
                font: {
                    size: 20
                }
            }
        },
        labels: { precision: 0, indent: 10 }
    });

    $('#redLevel').jqxSlider({theme: "arctic", mode: "fixed", min: 0, max: 255, ticksFrequency: 25.5, value: 170, step: 25.5 });
    $('#greenLevel').jqxSlider({ theme: "arctic", mode: "fixed", min: 0, max: 255, ticksFrequency: 25.5, value: 255, step: 25.5 });
    $('#blueLevel').jqxSlider({ theme: "arctic", mode: "fixed", min: 0, max: 255, ticksFrequency: 25.5, value: 187, step: 25.5 });

    var setColor = function ()
    {
        var red = $('#redLevel').val();
        var green = $('#greenLevel').val();
        var blue = $('#blueLevel').val();
        $('#barGauge').val(new Array(blue, green, red));
    }

    $('#redLevel').on('change', function (event)
    {
        setColor();
    });
    $('#greenLevel').on('change', function (event)
    {
        setColor();
    });
    $('#blueLevel').on('change', function (event)
    {
        setColor();
    });
});

body.html

<div id="barGauge"></div>
<div style="float: left">
    <span style="font-style: italic;">Red</span>
    <div id="redLevel">
    </div>
    <span style="font-style: italic;">Green</span>
    <div id="greenLevel">
    </div>
    <span style="font-style: italic;">Blue</span>
    <div id="blueLevel">
    </div>
</div>

Learn more

More jQuery BarGauge demos