About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

 

Download
Get the latest version of RGraph (version 6.16) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

Odometer chart

Example

An Odometer chart
<script>
    new RGraph.Odometer({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 18, // The value can be either a number or an array of numbers
        options: {
            colorsGreenMax: 75,
            colorsRedMin: 90,
            labelsAreaWidth: 50,
            needleThickness: 2,
            shadowOuter: true,
            shadowOuterColor: '#bbb',
            shadowOuterBlur: 2
        }
    }).draw();
</script>

Properties

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

Chart configuration properties

Name: border
Description: 
This controls the grey border of the Odometer chart.
Default: true
Name: tickmarks
Description: 
This controls whether tickmarks are shown. If you're animating the Odometer chart you'll need to turn this off.
Default: false
Name: tickmarksHighlighted
Description: 
This controls whether the tickmarks are highlighted in red/yellow/green.
Default: true
Name: centerx
Description: 
If required, you can position the Odometer chart using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the meter, this can also be a string like this: centerx: '+25' or this: centerx: '-40' which is then used to adjust the calculated coordinate.
Default: null
Name: centery
Description: 
If required, you can position the Odometer chart using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the meter, this can also be a string like this: centery: '+25' or this: centery: '-40' which is then used to adjust the calculated coordinate.
Default: null
Name: radius
Description: 
If required, you can size the Odometer chart using this instead of the margins. As well as a number, that gives the exact size of the meter, this can also be a string like this: radius: '+25' or this: radius: '-40' which is then used to adjust the calculated coordinate.
Default: null

Margin properties

Name: marginLeft
Description: 
The left margin of the chart, (the margin is where the labels and title are)).
Default: 35
Name: marginRight
Description: 
The right margin of the chart, (the margin is where the labels and title are).
Default: 35
Name: marginTop
Description: 
The top margin of the chart, (the margin is where the labels and title are).
Default: 35
Name: marginBottom
Description: 
The bottom margin of the chart, (the margin is where the labels and title are).
Default: 35

Color properties

Name: backgroundColor
Description: 
The color of the background of the chart.
Default: #BEBCB0
Name: borderColor1
Description: 
This is the first color used in the gradient of the outer border of the chart (if enabled).
Default: #BEBCB0
Name: borderColor2
Description: 
This is the second/middle color used in the gradient of the outer border of the chart (if enabled).
Default: #F0EFEA
Name: borderColor3
Description: 
This is the third color used in the gradient of the outer border of the chart (if enabled).
Default: #BEBCB0
Name: colorsGreenColor
Description: 
This is the color of the green area.
Default: green
Name: colorsGreenMax
Description: 
This is the point at which the green area ends.
Default: 75% of the maximum value
Name: colorsRedColor
Description: 
This is the color of the red area.
Default: red
Name: colorsRedMin
Description: 
This is the point at which the red area starts. The yellow area is between the green and red areas.
Default: 90% of the maximum value
Name: colorsYellowColor
Description: 
This is the color of the yellow area.
Default: yellow

Scale properties

Name: scaleUnitsPre
Description: 
The units that the value is measured in. This string is displayed before the actual number, allowing you to specify values such as $50 and is only used if valueText is true.
Default: none
Name: scaleUnitsPost
Description: 
The units that the value is measured in. This string is displayed after the actual number, allowing you to specify values such as 50ms and is only used if valueText is true.
Default: none
Name: scaleDecimals
Description: 
The number of decimal places to display for the labels.
Default:  0
Name: scalePoint
Description: 
The character that's used as the decimal point.
Default: .
Name: scaleThousand
Description: 
The character that's used as the thousand separator.
Default: ,

Labels and text properties

Name: labels
Description: 
Instead of using computed numbers, which uses the maximum value, you can specify the Odometer to use textual labels instead, with this option.
Default: null
Name: labelsValue
Description: 
Controls whether the value is indicated as a text label in the center of the dial.
Default: false
Name: labelsValueDecimals
Description: 
The number of decimals that are used by the valueText label.
Default:  0
Name: labelsValuePoint
Description: 
The character that's used as the decimal point.
Default: .
Name: labelsValueThousand
Description: 
The character that's used as the thousand separator.
Default: ,
Name: labelsValueUnitsPre
Description: 
The pre units that are used on the textual value.
Default: An empty string
Name: labelsValueUnitsPost
Description: 
The post units that are used on the textual value.
Default: An empty string
Name: labelsValueFont
Description: 
The font used to render the value label.
Default: null
Name: labelsValueSize
Description: 
The size of the value label.
Default: null
Name: labelsValueColor
Description: 
The color of the value label.
Default: null
Name: labelsValueBold
Description: 
Whether the value label is bold or not.
Default: null
Name: labelsValueItalic
Description: 
Whether the value label is italic or not.
Default: null
Name: labelsValueOffsetx
Description: 
This allows you finer-grained control in the horizontal direction over the text positioning if you need it.
Default:  0
Name: labelsValueOffsety
Description: 
This allows you finer-grained control in the vertical direction over the text positioning if you need it.
Default:  0
Name: labelsMargin
Description: 
The width of the area that labels are put in.
Default: 35
Name: textSize
Description: 
The size of the text (in points).
Default: 12
Name: textFont
Description: 
The font used to render the text.
Default: Arial, Verdana, sans-serif
Name: textColor
Description: 
The color of the labels.
Default: black
Name: textBold
Description: 
Whether the labels on the chart are bold or not.
Default: false
Name: textItalic
Description: 
Whether the labels on the chart are italic or not.
Default: false
Name: textAccessible
Description: 
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: false
Name: textAccessibleOverflow
Description: 
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 margins if you wish.
Default: visible
Name: textAccessiblePointerevents
Description: 
This controls whether the dom text responds to mouse-based events or not (it sets the pointer-events css property to none).
Default: true
Name: text
Description: 
This allows you to add custom text to your chart if you want to. There's a dedicated page that describes this option here.
Default: null

Needle properties

Name: needleWidth
Description: 
How thick the needle is. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: 2
Name: needleLength
Description: 
The length of the needle. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: null
Name: needleColor
Description: 
The color that's applied to the needle. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: black
Name: needleHead
Description: 
This controls whether the arrowhead on the end of the needle is displayed. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: true
Name: needleTail
Description: 
This controls whether the tail of the needle is displayed or not. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: true
Name: needleType
Description: 
This determines which type of needle is used. It can be pointer or triangle. This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: pointer
Name: needleTriangleBorder
Description: 
This controls the color of the border for the pointer. If you don't want it you could set it to be transparent: rgba(0,0,0,0). This can be both a number and an array of numbers (for when you're showing multiple needles).
Default: #aaa

Title properties

Name: title
Description: 
The title of the chart, if any.
Default: null
Name: titleFont
Description: 
The font that the title is rendered in. If not specified the textFont setting is used (usually Arial).
Default: null
Name: titleSize
Description: 
The size of the title. If not specified the size is usually 4pt bigger than the textSize setting.
Default: null
Name: titleBold
Description: 
Whether the title is bold or not.
Default: null
Name: titleItalic
Description: 
Whether the title is italic or not.
Default: null
Name: titleColor
Description: 
The color of the title.
Default: null
Name: titleX
Description: 
To give the exact X coordinate for the title - use this. This can also be a string like this: "-5" - in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null
Name: titleY
Description: 
To give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" - in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null
Name: titleHalign
Description: 
The horizontal alignment of the title.
Default: center (can change depending on other options)
Name: titleValign
Description: 
The vertical alignment of the title.
Default: center (can change depending on other options)
Name: titleOffsetx
Description: 
You can use this property to adjust the positioning of the title in the horizontal direction (positive values adjust the title to the right and negative values adjust it to the left).
Default:  0
Name: titleOffsety
Description: 
You can use this property to adjust the positioning of the title in the vertical direction (positive values adjust the title downwards and negative values adjust it upwards).
Default:  0
Name: titleSubtitle
Description: 
The subtitle of the chart. If a subtitle is specified the title is moved up to accommodate it. As such you might need to give a larger marginTop value.
Default: null
Name: titleSubtitleSize
Description: 
The size of the font used to render the subtitle.
Default: null
Name: titleSubtitleColor
Description: 
The color of the subtitle.
Default: #aaa
Name: titleSubtitleFont
Description: 
The font used to render the subtitle.
Default: null
Name: titleSubtitleBold
Description: 
Whether the subtitle is bold or not.
Default: null
Name: titleSubtitleItalic
Description: 
Whether the subtitle is italic or not.
Default: null
Name: titleSubtitleOffsetx
Description: 
Use this property to adjust the horizontal position of the subtitle.
Default:  0
Name: titleSubtitleOffsety
Description: 
Use this property to adjust the vertical position of the subtitle.
Default:  0

Shadow properties

Name: shadowInner
Description: 
Whether a drop shadow is applied to the inner circle of the Odometer.
Default: false
Name: shadowInnerColor
Description: 
The color for the inner shadow.
Default: black
Name: shadowInnerOffsetx
Description: 
The horizontal offset for the inner shadow.
Default: 3
Name: shadowInnerOffsety
Description: 
The vertical offset for the inner shadow.
Default: 3
Name: shadowInnerBlur
Description: 
The extent of the blurring effect on the shadow.
Default: 6
Name: shadowOuter
Description: 
Whether a drop shadow is applied to the whole Odometer.
Default: false
Name: shadowOuterColor
Description: 
The color for the outer shadow.
Default: black
Name: shadowOuterOffsetx
Description: 
The horizontal offset for the outer shadow.
Default: 3
Name: shadowOuterOffsety
Description: 
The vertical offset for the outer shadow.
Default: 3
Name: shadowOuterBlur
Description: 
The extent of the blurring effect on the shadow.
Default: 6

Interactive features properties

Name: contextmenu
Description: 
An array of context menu items. More information about context menus is here.
Default: An empty array
Name: annotatable
Description: 
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false
Name: annotatableColor
Description: 
If you do not allow the use of the palette, then this will be the only color allowed for annotations.
Default: black
Name: annotatableLinewidth
Description: 
This is the linewidth of the annotations.
Default: 1
Name: adjustable
Description: 
You can make the Odometer interactively adjustable by setting this to true.
Default: false

Miscellaneous properties

Name: clearto
Description: 
This is used in animations and effects as the default color to use when the canvas.
Default: null
Name: responsive
Description: 
This option is new to the July 2023 release (v6.13) and allows you to inline the responsive configuration instead of appending it on to the end of the object it as a function. The documentation and demo pages have been updated to use this new option. You can read more about the responsive feature by reading the responsive configuration page.
Default: null

Methods

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

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

obj.getAngle(value)
This method will return you an appropriate angle for the given value.

obj.on(event, function)

This method can be used to set an event listener on an object. It operates similarly to the jquery on function. The first argument is the event that you wish to attach to and the second is the handler function. For example:

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

The function is useful if you use method chaining when creating your charts:

var obj = new RGraph.Odometer({
    id: 'cvs',
    min: 0,
    max: 100,
    value: 56,
    options: {
    }
}).on('draw', function (e, shape)
{
    // Put draw event code here
})
.on('click', function (e, shape)
{
    // Handle click event
}).draw();
The exec option and method

The exec function is documented here.

obj.responsive(configuration)

The responsive function helps your charts respond to different browser window sizes and screen resolutions. For example, for smaller screens, you might want to have angled labels or show shorter versions of them completely.

Update: There is now the responsive configuration option available to you and this is now the preferred method of configuration.

The responsive function and configuration option are documented on their own page here.

Events

RGraph supports custom events that allow you to easily add interactivity to your charts if required. The following events are available:

For example:
new RGraph.Odometer({
    id: 'cvs',
    min: 0,
    max: 100,
    value: 47,
    options: {
    }
}).on('draw', function (obj)
{
    console.log('The draw event has fired');
    
}).draw();

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>
    window.onload = (function ()
    {
        //
        // Optional callback function that's called when the effect is complete
        //
        function myCallback (obj)
        {
            // ...
        }
    
        new RGraph.Odometer({
            id: 'cvs',
            min: 0,
            max: 100,
            value: 56,
            options: {
                marginLeft: 35
            }
        }).grow({frames: 60}, myCallback);
    });
</script>