Example
Variant selection
Features
- No images, no external CSS - pure canvas
- No dependencies (jQuery is supported, but not required)
- Highly configurable
- Resolution independent
- Animated guage value changes (!)
- Works in all major browsers
- MIT License
Usage
var opts = {
lines: 12, // The number of lines to draw
angle: 7, // The length of each line
lineWidth: 5, // The line thickness
pointer: {
length: 10, // The radius of the inner circle
strokeWidth: 0, // The rotation offset
color: '#000000' // Fill color
},
limitMax: 'false', // If true, the pointer will not go past the end of the gauge
colorStart: '0', // Colors
colorStop: '0', // just experiment with them
strokeColor: '0', // to see which ones work best for you
generateGradient: true
};
var target = document.getElementById('foo'); // your canvas element
var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
gauge.maxValue = 3000; // set max gauge value
gauge.animationSpeed = 3000; // set animation speed (32 is default value)
gauge.set(1500); // set actual value
The Gauge class handles drawing on canvas and starts the animation.
Advanced options
-
Percentage color
If you want to control how Gauge behavaes in relation to the displayed value you can use the Guage option called percentColors. To use it add following entry to the options:
percentColors = [[0.0, "#a9d70b" ], [0.50, "#f9c802"], [1.0, "#ff0000"]];
see working example at JSFiddle
jQuery plugin
Gauge.js does not require jQuery. Anyway, if you use jQuery you may use the following plugin:
$.fn.gauge = function(opts) {
this.each(function() {
var $this = $(this),
data = $this.data();
if (data.gauge) {
data.gauge.stop();
delete data.gauge;
}
if (opts !== false) {
data.gauge = new Gauge(this).setOptions(opts);
}
});
return this;
};
浏览器兼容
Gauge.js has been (not yet!) successfully tested in the following browsers:
- Chrome
- Safari 3.2+
- Firefox 3.5+
- IE 9
- Opera 10.6+
- Mobile Safari (iOS 3.2+)
- Android 2.3+