RGraph is a JavaScript charts library based on
HTML5 SVG and canvas. RGraph is mature (over 17 years
old) and has a wealth of features making it an ideal
choice to use for showing charts on your website.
Version 7.01 (released in October 2025) is the
latest version of RGraph and now includes a new tree
structure object. The accompanying Treemenu object can then turn
the object into a fully dynamic tree menu.
You can read the API documentation for the tree on
the main API documentation page
and see an example of the Treemenu
feature by following this link...
In the April 2025 (v6.21) release a new datagrid object
was added.
This makes it easy to add static or dynamic data
tables to your pages. It can be used whether you use the
canvas or SVG libraries or entirely standalone.
Get the latest version of RGraph (version 7.01, 8th October 2025) 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.
<script>
// Create the Fuel chart. The arguments are: the minimum value, the maximum value, and the actual value.
new RGraph.Fuel({
id: 'cvs',
min: 0,
max: 100,
value: 77,
options: {
needleColor: 'blue',
colors: ['#ddf'],
labelsEmpty: 'Empty!',
labelsFull: 'Full',
icon: '/images/water-droplet.png',
centery: '-50',
radius: '-50'
}
}).grow();
</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 Fuel gauge using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the gauge, 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 Fuel gauge using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the gauge, 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 Fuel gauge using this instead of the margins. As well as a number, that gives the exact size of the gauge, 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
Color properties
Name: colors
Description:
The color of the Fuel Gauge. Note that despite there being only one color, this is still an array.
Default: ['red']
Margin properties
Name: marginLeft
Description:
The left margin of the chart, (the margin is where the labels and title are)).
Default: 5
Name: marginRight
Description:
The right margin of the chart, (the margin is where the labels and title are).
Default: 5
Name: marginTop
Description:
The top margin of the chart, (the margin is where the labels and title are).
Default: 5
Name: marginBottom
Description:
The bottom margin of the chart, (the margin is where the labels and title are).
Default: 5
Needle properties
Name: needleColor
Description:
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
Name: needleRadiusOffset
Description:
By increasing this you can shorten the needle and by decreasing it you can lengthen the needle.
Default: 45
Labels and text properties
Name: labelsEmpty
Description:
The text that's used as the empty label.
Default: E
Name: labelsEmptyOffsetx
Description:
This allows you finer-grained control in the horizontal direction over the text positioning if you need it.
Default: 0
Name: labelsEmptyOffsety
Description:
This allows you finer-grained control in the vertical direction over the text positioning if you need it.
Default: 0
Name: labelsFull
Description:
The text used as the full label.
Default: F
Name: labelsFullOffsetx
Description:
This allows you finer-grained control in the horizontal direction over the text positioning if you need it.
Default: 0
Name: labelsFullOffsety
Description:
This allows you finer-grained control in the vertical direction over the text positioning if you need it.
Default: 0
Name: labelsColor
Description:
The color used for the text on the chart.
Default: null
Name: labelsFont
Description:
The font used for the text.
Default: null
Name: labelsSize
Description:
The size of the text.
Default: null
Name: labelsBold
Description:
Whether the labels are bold or not.
Default: null
Name: labelsItalic
Description:
Whether the labels are italic or not.
Default: null
Name: textColor
Description:
The color used for the text on the chart.
Default: black
Name: textFont
Description:
The font used for the text.
Default: Arial
Name: textSize
Description:
The size of the text.
Default: 12
Name: textBold
Description:
Whether the labels are bold or not.
Default: false
Name: textItalic
Description:
Whether the labels 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:
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).
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:
Whether the Fuel chart is adjustable or not.
Default: false
Miscellaneous properties
Name: icon
Description:
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]
Name: iconRedraw
Description:
If false then the chart is NOT redrawn when the image/icon loads. You may need to set this to false if you use the adjusting feature.
Default: true
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
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: scale
Description:
Whether scaling is enabled or not. Scaling makes the canvas look a lot better and it's recommended that this be left enabled unless you want the old, pre-version 7 style of antaliasing.
Default: true
Name: scaleFactor
Description:
How much the canvas is scaled by when it's scaled. The default value of 2 is the recommended amount.
Default: 2
Name: antialiasTranslate
Description:
If for some reason you want the old style of antialiasing then you can set this property to true. You will also need to turn off scaling by setting the scale property to false. You might not see a huge difference on charts that don't have straight lines (eg circular gauges and meters).
Default: false
Methods
Name: mixed get(string name)
Description:
An accessor that you can use to retrieve the values of properties.
Name: object set(string name, mixed value)
Description:
An accessor that you can use to set the values of properties.
This method can be used to add an event listener to your object. It operates similarly to the jquery on function. The first argument is the event that you want to attach to and the second is the handler function. For example:
.on('draw', function (obj)
{
// Put your code here. Depending on the event, you can sometimes// get meta information from the RGraph registry. See the list// of event types below for more detail.
});
You can also use the new (added in version 6.22)
events property to add events and that looks
like this:
new RGraph.Fuel({
id: 'cvs',
min: 0,
max: 100,
value: 67,
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();
Name: object responsive(object configuration)
Description:
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.
Name: number getAngle(number value)
Description:
This method can be used to get the angle for a value when
you're doing custom drawing on the chart. It returns
null if the value is out of range.
The coordinates properties
As with the majority of the RGraph objects the
coordinates of the various shapes are recorded and
stored in various properties on the RGraph chart object.
In the case of the Fuel chart the
coordinates of text are recorded as usual in the
obj.coordsText variable and the start
angle, the end angle and the radius are recorded in the
obj.angles property.
obj.angles This is an object the holds
the following properties:
start The start angle (measured
in radians) of the scale.
end The end angle (measured
in radians) of the scale.
needle The angle (measured
in radians) that the needle is
positioned at.
obj.coordsText This holds the
coordinates of all of the text that has been added
to the chart. Even if the text is blank (ie no text)
then the coordinates will be added to this variable.
Events
RGraph supports custom events that allow you to easily add interactivity to your charts if
required. The following events are available:
Name: adjustbegin
Description:
This event fires at the start of adjusting - like the standard mousedown event.
Name: adjust
Description:
This event fires (repeatedly) during adjusting - like the standard mousemove event.
Name: adjustend
Description:
This event fires at the end of adjusting - like the standard mouseup event.
Name: annotatebegin
Description:
This event fires at the start of annotating - like the standard mousedown event.
Name: annotate
Description:
This event fires (repeatedly) during annotating - like the standard mousemove event.
Name: annotateend
Description:
This event fires at the end of annotating - like the standard mouseup event.
Name: annotateclear
Description:
This event fires at the end of the RGraph.clearAnnotations function.
Name: beforeclear
Description:
This event fires at the start of the RGraph.clear function.
Name: clear
Description:
This event fires at the end of the RGraph.clear function.
Name: beforecontextmenu
Description:
This event fires when you have the contextmenu enabled and it is about to appear.
Name: contextmenu
Description:
This event fires when you have the contextmenu enabled and it has been displayed.
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 that the draw function is called.
Name: draw
Description:
This event fires at the end of the draw function.
For example:
new RGraph.Fuel({
id: 'cvs',
min: 0,
max: 50,
value: 34,
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();
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
There's a stopAnimation() function that you can
use to stop an animation immediately if you need to.
There's a line chart demo called
demos/line-effects-stop-animation.html in
the download archive
that demonstrates the use of this function.