Fuel gauge documentation

Recommend RGraph:  
    Read comments...

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.

 

Chart configuration

centerx
If required, you can position the Fuel chart using this instead of the gutters.
Default: null

centery
If required, you can position the Fuel chart using this instead of the gutters.
Default: null

radius
If required, you can size the Fuel chart using this instead of the gutters.
Default: null

 

Colors

colors
The color of the Fuel Gauge. Note that despite there being only one color, this is still an array.
Default: ['red']

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 5

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 5

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 5

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 5

 

Needle options

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

 

Labels and text

labelsEmpty
The label used as the empty text.
Default: E

labelsFull
The label used as the full text.
Default: F

labelsCount
Instead of the Empty/Full labels you can use this to have a scale instead. You'll also need to set scale.visible.
Default: 5

textColor
The color used for the text on the chart.
Default: black

textFont
The font used for the text.
Default: Arial

textAccessible
A 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>

Default: true

textAccessibleOverflow
This 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.
Default: visible

textAccessiblePointerevents
This controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).
Default: true

 

Scale

scaleVisible
Instead of the Full/Empty labels you can set this to true to show a scale instead.
Default: false

scaleDecimals
This determines how many decimal places are shown in the scale.
Default: 0

unitsPre
The units that the Y axis is measured in. This string is displayed BEFORE the actual number, allowing you to specify values such as "$50".
Default: none

unitsPost
The units that the Y axis is measured in. This string is displayed AFTER the actual number, allowing you to specify values such as "50ms".
Default: none

 

Interactive features

contextmenu
The context menu. For more details see here.
Default: null

annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false

annotateColor
If you do not allow the use of the palette, then this will be the only colour allowed for annotations.
Default: black

annotateLinewidth
This is the line width of the annotations.
Default: 1

adjustable
Whether the Fuel chart is adjustable or not.
Default: false

resizable
Defaulting 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).
Default: false

resizeHandleBackground
With 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.
Default: null

resizableMaxwidth
This allows you to set a maximum width that the chart can be resized to.
Default: null

resizableMaxheight
This allows you to set a maximum height that the chart can be resized to.
Default: null

 

Zoom

zoomFactor
This is the factor that the chart will be zoomed by (bigger values means more zoom)
Default: 1.5

zoomFadeIn
Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomFadeOut
Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomHdir
The horizontal direction of the zoom. Possible values are: left, center, right
Default: right

zoomVdir
The vertical direction of the zoom. Possible values are: up, center, down
Default: down

zoomDelay
The delay (in milliseconds) between frames.
Default: 50

zoomFrames
The number of frames in the zoom animation.
Default: 10

zoomShadow
Whether or not the zoomed canvas has a shadow or not.
Default: true

 

Miscellaneous

icon
This 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.
Default: [A data: URL of a fuel icon]

iconRedraw
If false, then the chart is NOT redrawn when the image/icon loads. You may need to set this to false if you use adjusting.
Default: true

clearto
This is used in animations and effects as the default color to use when the canvas.
Default: 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>

Comments