RGraph is a JavaScript charts library based on
HTML5 SVG and canvas. RGraph is mature (over 18 years
old) and has a wealth of features making it an ideal
choice to use for showing charts on your website.
Version 7.20 (released in June 2026) is the
latest version of RGraph and the major change in
this version is an update to the default values
of properties making for better looking charts without
having to set any properties.
Read more about this and other changes in
the changelog.
Get the latest version of RGraph (version 7.20, 9th June 2026) from
the download page. You can read the changelog here. There's also older versions available,
minified files and links to cdnjs.com hosted libraries.
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:
obj.nodes.background
obj.nodes.labelsIngraph
obj.nodes.labelsIngraphGroup
obj.nodes.needleGroup
obj.nodes.innerAxis
obj.nodes.innerAxisGroup
obj.nodes.outerAxis
obj.nodes.outerAxisGroup
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.
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: #ddd
Name: backgroundGrid
Description:
Whether the background grid is enabled or not.
Default: true
Name: backgroundGridColor
Description:
The color of the background grid.
Default: #aaa
Color properties
Name: colors
Description:
The colors of the axes. This should be an array of two strings. Gradients cannot be used here.
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: [an empty string]
Name: labelsIngraphUnitsPost
Description:
Units that are appended to the ingraph label.
Default: [an empty string]
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: [an empty string]
Name: scaleInnerUnitsPost
Description:
Units for the label that are prepended to the number.
Default: [an empty string]
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: [an empty string]
Name: scaleOuterUnitsPost
Description:
Units for the label that are prepended to the number.
Default: [an empty string]
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
Name: titleSubtitleOffsetx
Description:
An offset value that's added to the calculated X-axis coordinate.
Default: 0
Name: titleSubtitleOffsety
Description:
An offset value that's added to the calculated Y-axis coordinate.
Default: 0
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
Shadow properties
Name: shadow
Description:
Whether the Gauge has a shadow or not.
Default: false
Name: shadowOffsetx
Description:
The horizontal offset of the shadow.
Default: 2
Name: shadowOffsety
Description:
The vertical offset of the shadow.
Default: 2
Name: shadowBlur
Description:
The severity of the blurring effect that the shadow has.
Default: 2
Name: shadowColor
Description:
The color of the shadow.
Default: rgba(0,0,0,0.25)
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: needleLength
Description:
This is the length of the needle. By default, it's calculated to fit the size of the Gauge.
Default: null
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
Name: zoom
Description:
Allow zooming of the chart. The SVG zoom feature, added in version 6.19, allows you to zoom in on a certain area of your chart and then pan around by dragging the zoom. You can also increase or decrease the zoom level by using your mousewheel if you have one. You can read a documentation page about the SVG zoom feature here.
Default: false
Name: events
Description:
This option is new to version 6.22 and allows you to specify event listener functions for the various RGraph events (eg beforedraw, firstdraw, draw etc). There's an example of its usage in the events section below. It's an object and the properties are the names of the events. The values of those properties can either be the function that you want to attach to the event or an array of functions that you want to run.
Default: {}
Name: clip
Description:
Clipping allows you to restrict whatever is added to the drawing surface to a particular area. For example if you specify lefthalf to the clip property then you'll see only the left half of the SVG - usually the left half of the chart, though this depends on your margin settings. You can read more information about this option and a list of the possible values that are available to you on the clipping documentation page.
Default: null
Name: style
Description:
This allows you add standard CSS styles to the document from within the chart configuration. You may want to keep your styles that are related to your chart (for example, the tooltip styles) together with the chart configuration.. The syntax looks like:
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).
Name: object set(string name, mixed value)
Description:
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. The return value is the chart object so you can chain your set calls if you wish
Name: object on(event name, function handler)
Description:
This function adds an event listener (such as beforedraw draw or tooltip) to the chart object. For example:
obj.on('draw', function (obj)
{
// Put your code here
});
You can also use the new (added in version 6.22)
events property to add events and that looks
like this:
<script>
new RGraph.SVG.Gauge({
id: 'chart-container',
innerMin: 0,
innerMax: 10,
outerMin: 0,
outerMax: 100,
value: 56,
options: {
events: {
beforedraw: function () {alert('The beforedraw event fired');},
draw: [
function (obj) {alert('The first draw event listener function.');},
function (obj) {alert('The second draw event listener function.');}
]
}
}
}).draw();
</script>
Name: object exec(function func)
Description:
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 RGraph.SVG.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
});
Update:
There is now the responsive configuration option available to you
and this is now the preferred method of configuration.
Events
RGraph supports custom events that allow you to easily add interactivity to your charts if
required. The following events are available:
Name: beforedraw
Description:
This event fires at the start of the draw method before anything has been done.
Name: firstdraw
Description:
This event fires at the end of the draw function - but only the first time and so it fires only once after the first draw call.
Name: draw
Description:
This event fires at the end of the draw function.
Name: adjustbegin
Description:
This event fires at the start of adjusting.
Name: adjust
Description:
This event fires (repeatedly) during adjusting.
Name: adjustend
Description:
This event fires at the end of adjusting.
For example:
new RGraph.SVG.Gauge({
id: 'chart-container',
innerMin: 0,
innerMax: 100,
outerMin: 0,
outerMax: 10,
value: 78,
options: {
events: {
draw: function (obj){console.log('The draw event has fired');},
// Alternatively you can give an array of functions to run
firstdraw: [
function (obj) {console.log('First function');},
function (obj) {console.log('Second function');}
]
}
}
}).draw();