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 »

 

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

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 »

Gauge chart API reference

Example

<script>
    new RGraph.SVG.Gauge({
        id: 'chart-container',
        innerMin: 0,
        innerMax: 10,
        outerMin: 0,
        outerMax: 100,
        value: 7.8,
        options: {
            adjustable: true,
            centerpinRadius: 10,
            labelsIngraphUnitsPost: '%',
            labelsIngraphDecimals: 1,
            colors: ['red','blue'],
            marginTop: 15,
            marginBottom: 15,
            marginLeft: 15,
            marginRight: 15
        }
    }).draw();
</script>

The obj.nodes property

Instead of coordinates the Gauge chart maintains references to the nodes that are created - such as the axes, the labels and text nodes. For example:

For example, you could add your own event listeners like this:

<script>
    obj.nodes.needleGroup.onclick = function (e)
    {
        alert('The value is: ' + obj.value);
    }
</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: centerx
Description: 
If required, you can position the Gauge chart using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the chart, 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 Gauge chart using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the chart, 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 Gauge chart using this instead of the margins. As well as a number, that gives the exact size of the chart, this can also be a string like this: radius: '+25' or this: radius: '-40' which is then used to adjust the calculated size.
Default: null

Margin properties

Name: marginLeft
Description: 
The left margin of the chart).
Default: 35
Name: marginRight
Description: 
The right margin of the chart.
Default: 35
Name: marginTop
Description: 
The top margin of the chart.
Default: 35
Name: marginBottom
Description: 
The bottom margin of the chart.
Default: 35
Name: rmargin
Description: 
This is the area that the outer scale sits in. By default, it is calculated at either 25 or 40 depending on whether the outer scale is enabled or not.
Default: null

Background properties

Name: backgroundStroke
Description: 
The color of the background stroke color.
Default: #ddd
Name: backgroundFill
Description: 
The color of the background fill color.
Default: Gradient(white:#FEFEFE:#E6E6E6:#dedede)
Name: backgroundGrid
Description: 
Whether the background grid is enabled or not.
Default: true
Name: backgroundGridColor
Description: 
The color of the background grid.
Default: #ddd

Color properties

Name: colors
Description: 
The colors of the axes. This should be an array of two strings. Gradients cannot be used here.
Default: ['black','black']

Other text properties

Name: textFont
Description: 
The font used to render the text.
Default: Arial, Verdana, sans-serif
Name: textSize
Description: 
The size of the text.
Default: 12
Name: textColor
Description: 
The color of the labels.
Default: black
Name: textItalic
Description: 
Whether the labels are italic or not.
Default: false
Name: textBold
Description: 
Whether the labels are bold or not.
Default: false
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
Name: labelsIngraph
Description: 
Whether the ingraph label (in the center of the chart) is displayed.
Default: true
Name: labelsIngraphFont
Description: 
The font to use to render the text for the ingraph label.
Default: null
Name: labelsIngraphSize
Description: 
The font size to use to render the text for the ingraph label.
Default: null
Name: labelsIngraphBold
Description: 
Whether the ingraph label should be bold or not.
Default: null
Name: labelsIngraphItalic
Description: 
Whether the ingraph label should be italic or not.
Default: null
Name: labelsIngraphColor
Description: 
The color of the ingraph label.
Default: null
Name: labelsIngraphUnitsPre
Description: 
Units that are prepended to the ingraph label.
Default: none
Name: labelsIngraphUnitsPost
Description: 
Units that are appended to the ingraph label.
Default: none
Name: labelsIngraphThousand
Description: 
The character(s) used as the thousand separator.
Default: ,
Name: labelsIngraphPoint
Description: 
The character(s) used as the decimal point.
Default: .
Name: labelsIngraphFormatter
Description: 
This can be a function that is used to handle all of the label formatting. It's passed the number as an argument.
Default: null
Name: labelsIngraphDecimals
Description: 
This should be a number that dictates how many decimal places are displayed.
Default:  0
Name: labelsIngraphPadding
Description: 
Padding that is applied to the number.
Default: 3
Name: labelsIngraphBackground
Description: 
The color of the background for the label.
Default: Gradient(#ddd:#eee)
Name: labelsIngraphRounded
Description: 
The severity of the rounded corners effect of the label.
Default: 2

Scale properties

Name: scaleInnerFont
Description: 
The font used to render the text.
Default: null
Name: scaleInnerSize
Description: 
The size of the text.
Default: null
Name: scaleInnerBold
Description: 
Whether the text is bold or not.
Default: null
Name: scaleInnerItalic
Description: 
Whether the text is italic or not.
Default: null
Name: scaleInnerColor
Description: 
The color of the text.
Default: null
Name: scaleInnerDecimals
Description: 
The number of decimals used by the labels.
Default:  0
Name: scaleInnerUnitsPre
Description: 
Units for the label that are prepended to the number.
Default: (none)
Name: scaleInnerUnitsPost
Description: 
Units for the label that are prepended to the number.
Default: (none)
Name: scaleInnerPoint
Description: 
The character(s) used for the decimal point.
Default: .
Name: scaleInnerThousand
Description: 
The character(s) used as the thousand separator.
Default: ,
Name: scaleInnerFormatter
Description: 
This can be a function that entirely handles the formatting of the number.
Default: null
Name: scaleInnerLabelsCount
Description: 
The number of labels that are displayed.
Default: 10
Name: scaleOuter
Description: 
Whether the outer scale is displayed or not.
Default: true
Name: scaleOuterFont
Description: 
The font used to render the text.
Default: null
Name: scaleOuterSize
Description: 
The size of the text.
Default: null
Name: scaleOuterBold
Description: 
Whether the text is bold or not.
Default: null
Name: scaleOuterItalic
Description: 
Whether the text is italic or not.
Default: null
Name: scaleOuterColor
Description: 
The color of the text.
Default: null
Name: scaleOuterDecimals
Description: 
The number of decimals used by the labels.
Default:  0
Name: scaleOuterUnitsPre
Description: 
Units for the label that are prepended to the number.
Default: (none)
Name: scaleOuterUnitsPost
Description: 
Units for the label that are prepended to the number.
Default: (none)
Name: scaleOuterPoint
Description: 
The character(s) used for the decimal point.
Default: .
Name: scaleOuterThousand
Description: 
The character(s) used as the thousand separator.
Default: ,
Name: scaleOuterFormatter
Description: 
This can be a function that entirely handles the formatting of the number.
Default: null
Name: scaleOuterLabelsCount
Description: 
The number of labels that are displayed.
Default: 10

Title properties

Name: title
Description: 
The title of the chart.
Default: (An empty string)
Name: titleX
Description: 
The specific x-axis coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.
Default: null
Name: titleY
Description: 
The specific y-axis coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.
Default: +5 (a string)
Name: titleOffsetx
Description: 
An offset value that is added to the calculated x-axis coordinate.
Default:  0
Name: titleOffsety
Description: 
An offset value that is added to the calculated y-axis coordinate.
Default:  0
Name: titleHalign
Description: 
The horizontal alignment of the title.
Default: center
Name: titleColor
Description: 
The color of the title.
Default: null
Name: titleFont
Description: 
The font used to render the title.
Default: null
Name: titleSize
Description: 
The size of the font used to render the title.
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: 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: (An empty string)
Name: titleSubtitleColor
Description: 
The color of the subtitle.
Default: #aaa
Name: titleSubtitleFont
Description: 
The font used to render the subtitle.
Default: null
Name: titleSubtitleSize
Description: 
The size of 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

Tickmark properties

Name: tickmarksOuterSize
Description: 
The size of the outer axis tickmarks.
Default: 3
Name: tickmarksInnerSize
Description: 
The size of the inner axis tickmarks.
Default: 3
Name: tickmarksCount
Description: 
The number of tickmarks that are displayed.
Default: 10

Other properties

Name: linewidth
Description: 
The linewidth of the axes.
Default: 1
Name: innerGap
Description: 
The size of the gap between the inner and outer circular axes.
Default: 5
Name: needleColor
Description: 
This is the color of the needle.
Default: #666
Name: centerpinRadius
Description: 
The radius of the circle that's at the center of the chart.
Default: 5
Name: adjustable
Description: 
If true then the gauge will be adjustable by clicking on it to select the value.
Default: false
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)

This can be used to get properties if necessary. It's normally used after the chart is drawn if you need to get parameters (if you're doing custom coding for example).

obj.set(name, value)

This can be used to set properties if necessary. It's normally used after the chart is drawn if you need to set additional parameters or change them.

obj.on(event, handler)

This function adds an event listener (such as beforedraw or draw) to the chart object. For example:

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

This function can be used to execute a function (immediately). It's not event-based (ie it doesn't run when something happens) - it just runs immediately - and only once. You might use it when you need to get something from the chart when it's drawn and then call the redraw function. Because this function only runs once the RGraph.SVG.redraw function would not cause a loop - which would happen if you used the draw event.

obj.exec(function (obj)
{
    // Put your code 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.SVG.Gauge({
    id: 'chart-container',
    innerMin: 0,
    innerMax: 100,
    outerMin: 0,
    outerMax: 10,
    value: 78,
    options: {
    }
}).on('draw', function (obj)
{
    console.log('The draw event has fired');
    
}).draw();