Auto changing values, related to the background color of the 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.
formatFunction property – Sets or gets the formatFunction of the BarGauge.height property – Sets or gets the BarGauge's height.relativeInnerRadius property – Sets or gets the relativeInnerRadius of jqxBarGauge.values property – Sets or gets array of values for the BarGauge.width property – Sets or gets the BarGauge's width.drawEnd event – The event is raised when the BarGauge finish rendering.val method – Returns an array of the BarGauge values.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.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
$(document).ready(function ()
{
var values = [];
var barGaugePalette = ['#307DD7', '#AA4643', '#89A54E', '#71588F', '#4198AF'];
$('#barGauge').jqxBarGauge({
width: getWidth('barGauge'),
height: getHeight('barGauge'),
values: [25],
relativeInnerRadius: 0.6,
formatFunction: function (value, index, color)
{
if (value < 20)
{
return barGaugePalette[0];
}
if (value < 40)
{
return barGaugePalette[1];
}
if (value < 60)
{
return barGaugePalette[2];
}
if (value < 80)
{
return barGaugePalette[3];
}
if (value <= 100)
{
return barGaugePalette[4];
}
}
});
var loop = 0;
$('#barGauge').on("drawEnd", function ()
{
values[0] = getRandomInt(1, 99);
setTimeout(function ()
{
$('#barGauge').jqxBarGauge("val", values);
}, 1000);
});
function getRandomInt(min, max)
{
return Math.floor(Math.random() * (max - min)) + min;
}
});
<div id="barGauge"></div>