Fuel gauge documentation

Share RGraph:   Share or Like RGraph on Facebook!

The Fuel gauge is recent addition to RGraph, and the available configuration options are shown here.

 

Example

<script>
    // Create the Fuel chart. The arguments are: the minimum, the maximum, and the value.
    var fuel = new RGraph.Fuel({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 67,
        options: {
            needleColor: 'blue',
            colors: ['#ddf'],
            labelsEmpty: 'Empty!',
            labelsFull: 'Full',
            icon: '/images/water.jpg'
        }
    }).draw();
</script>

The example file is here.

 

Properties

You can use these properties to control how the chart apears. You can set them by including them in the options section of the configuration as above.

Layout style:     
  

Chart configuration

PropertyDescriptionDefault
centerxIf required, you can position the Fuel chart using this instead of the gutters.null
centeryIf required, you can position the Fuel chart using this instead of the gutters.null
radiusIf required, you can size the Fuel chart using this instead of the gutters.null

Colors

PropertyDescriptionDefault
colorsThe color of the Fuel Gauge. Note that despite there being only one color, this is still an array.['red']

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the chart, (the gutter is where the labels and title are)).5
gutterRightThe right gutter of the chart, (the gutter is where the labels and title are).5
gutterTopThe top gutter of the chart, (the gutter is where the labels and title are).5
gutterBottomThe bottom gutter of the chart, (the gutter is where the labels and title are).5

Needle options

PropertyDescriptionDefault
needleColorThe color of the needle (not including the bulb at the bottom). Note that this is NOT an array - it's just a string.red

Labels and text

PropertyDescriptionDefault
labelsEmptyThe label used as the empty text.E
labelsFullThe label used as the full text.F
labelsCountInstead of the Empty/Full labels you can use this to have a scale instead. You'll also need to set scale.visible.5
textColorThe color used for the text on the chart.black
textFontThe font used for the text.Arial
textAccessibleA new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>
true
textAccessibleOverflowThis can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small gutters if you wish.visible
textAccessiblePointereventsThis controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).true

Scale

PropertyDescriptionDefault
scaleVisibleInstead of the Full/Empty labels you can set this to true to show a scale instead.false
scaleDecimalsThis determines how many decimal places are shown in the scale.0
unitsPreThe units that the Y axis is measured in. This string is displayed BEFORE the actual number, allowing you to specify values such as "$50".none
unitsPostThe units that the Y axis is measured in. This string is displayed AFTER the actual number, allowing you to specify values such as "50ms".none

Interactive features

PropertyDescriptionDefault
contextmenuThe context menu. For more details see here.null
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotateColorIf you do not allow the use of the palette, then this will be the only colour allowed for annotations.black
annotateLinewidthThis is the line width of the annotations.1
adjustableWhether the Fuel chart is adjustable or not.false
resizableDefaulting to false, this determines whether your chart will be resizable. Because of the numerous event handlers this has to install code on, This feature is unlikely to work with other dynamic features (the context menu is fine however).false
resizeHandleBackgroundWith this you can specify the background color for the resize handle. If you're adjusting the position of the handle then you may need this to make the handle stand out more.null
resizableMinwidthThis allows you to set a minimum width that the chart can be resized to.null
resizableMinheightThis allows you to set a minimum height that the chart can be resized to.null
resizableMaxwidthThis allows you to set a maximum width that the chart can be resized to.null
resizableMaxheightThis allows you to set a maximum height that the chart can be resized to.null

Zoom

PropertyDescriptionDefault
zoomFactorThis is the factor that the chart will be zoomed by (bigger values means more zoom)1.5
zoomFadeInWhether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomFadeOutWhether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomHdirThe horizontal direction of the zoom. Possible values are: left, center, rightright
zoomVdirThe vertical direction of the zoom. Possible values are: up, center, downdown
zoomDelayThe delay (in milliseconds) between frames.50
zoomFramesThe number of frames in the zoom animation.10
zoomShadowWhether or not the zoomed canvas has a shadow or not.true

Miscellaneous

PropertyDescriptionDefault
iconThis should be a URL that represents the image to use as the icon on the chart. The default fuel icon is a data: URL, though you can specify any valid image URL.[A data: URL of a fuel icon]
iconRedrawIf false, then the chart is NOT redrawn when the image/icon loads. You may need to set this to false if you use adjusting.true
cleartoThis is used in animations and effects as the default color to use when the canvas.null

 

Methods

 

obj.get(name)
An accessor that you can use to retrieve the value of properties.

 

obj.set(name, value)
An accessor that you can use to set the value of properties.

 

obj.getAngle(value)

This method can be used to get an appropriate angle for a value when you're doing custom drawing on the chart. It returns null if the value is out of range.

 

obj.on(event, func)

This method can be used to set an event listener on an object. It operates in a similar way to the jQuery .on() function - the first argument is the event you wish to attach to and the second is the handler function. For example:

.on('draw', function (obj)
{
    // Put event code here
});

 

The exec option and method

The exec function is documented here.

 

Animation Effects

These effects are available and can be used instead of the .draw() function. There are also generic effects available which you can see here: Generic effects and transitions
<script>
    /**
    * Optional callback function that's called when the effect is complete
    */
    function myCallback (obj)
    {
        // ...
    }

    var obj = new RGraph.Fuel({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 56,
        options: {
        }
    }).grow({frames: 60}, myCallback);
</script>