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.
Using a key on your chart allows you to provide information about what the
datasets that are displayed on the chart represent.
Keys can be used in two different modes -
a horizontal one designed to sit in the margins of the chart, and a vertical
one that is designed to sit over the chart.
Key configuration properties
The available key properties and their defaults are listed below
(some chart types have slightly different defaults to suit):
Name: key
Description:
An array of key elements (this is the text that is displayed in the key.
Default: [] (An empty array)
Name: keyHalign
Description:
The horizontal alignment of the key
Default: right
Name: keyValign
Description:
[Pie chart only] The vertical alignment of the key. By default this is null but you can set this to center in order to vertically center the key. There's a demo in the download archive that shows this called pie-vertically-centered-key.html This property takes precedence over the keyPositionY property.
Default: null
Name: keyPosition
Description:
This determines the positioning/layout of the key. Possible values are graph and margin.
Default: graph
Name: keyPositionMarginBoxed
Description:
When the key is in margin mode this determines if it sits in a box.
Default: false
Name: keyPositionMarginHSpace
Description:
When the key is in margin mode this adds horizontal space to the key items (ie they're more spaced out).
Default: 0
Name: keyPositionGraphBoxed
Description:
When the key is in graph mode this determines if it sits in a box.
Default: true
Name: keyPositionX
Description:
This allows you to specify an X coordinate for the key.
Default: null
Name: keyPositionY
Description:
This allows you to specify a Y coordinate for the key.
Default: null
Name: keyPositionOffsetx
Description:
This allows you to offset the X coordinate for the key by a given amount.
Default: null
Name: keyPositionOffsety
Description:
This allows you to offset the Y coordinate for the key by a given amount.
Default: null
Name: keyShadow
Description:
This controls whether the key has a shadow or not.
Default: false
Name: keyShadowOffsetx
Description:
This controls the X offset for the shadow.
Default: 2
Name: keyShadowOffsety
Description:
This controls the Y offset for the shadow.
Default: 2
Name: keyShadowColor
Description:
This controls the color of the shadow.
Default: #666
Name: keyShadowBlur
Description:
This controls the blur that's applied to the shadow.
Default: 3
Name: keyColors
Description:
If the calculated colors are not what you want to see - this allows you to specify your own colors.
Default: null
Name: keyColorShape
Description:
This is the shape that the color blob takes on.
Default: square (can be an array of shapes)
Name: keyBackground
Description:
The background of the key.
Default: white
Name: keyRounded
Description:
Whether the corners of the key are square or rounded.
Default: true
Name: keyLinewidth
Description:
The linewidth used for the key.
Default: 1
Name: keyLabelsFont
Description:
The font used for the key text.
Default: [same as the textFont setting]
Name: keyLabelsSize
Description:
The size of the text in the key.
Default: [same as the textSize setting]
Name: keyLabelsColor
Description:
The color of the text in the key.
Default: black
Name: keyLabelsBold
Description:
Whether the text in the key is bold or not.
Default: false
Name: keyLabelsItalic
Description:
Whether the text in the key is italic or not.
Default: false
Name: keyLabelsOffsetx
Description:
The offset that gets applied to the X coordinate to the key text.
Default: 0
Name: keyLabelsOffsety
Description:
The offset that gets applied to the Y coordinate to the key text.
Default: 0
Name: keyTextAccessible
Description:
By default the key text IS NOT accessible but by using this setting you can override this.
Default: null
Name: keyInteractive
Description:
Whether the key is interactive or not. Not all chart types support this.
Default: false
Name: keyInteractive
Description:
Whether the key is interactive or not. Not all chart types support this.
Default: false
Name: keyInteractiveHighlightChartLinewidth
Description:
The linewidth of the stroke that goes around the highlight on the chart.
Default: rgba(255,255,255,0.7)
Name: keyInteractiveHighlightChartFill
Description:
The highlight fill color that's used to highlight the chart by the interactive key.
Default: rgba(255,255,255,0.7)
Name: keyInteractiveHighlightChartStroke
Description:
The highlight stroke color that's used to highlight the chart by the interactive key.
Instead of the key code calculating the value - which might not be what you want in some cases - you can use this property to specify the exact values that you want to be used in the key (this specifies just the values - not the whole string).
Default: null
Name: keyFormattedItemsCount
Description:
You can use this property to specify the number of key items that should be shown. Normally this is calculated automatically for you.
Default: null
Active key elements
When you hover over or click on a key element/entry then the RGraph registry will
hold details of the relevant key entry. So in your event listener, you will be able
to determine the key entry like this:
key = RGraph.Registry.get('key-element');
And you could use it like this:
// Assume that the line variable is your line chart object
line.canvas.onmousemove = function (e)
{
var key = RGraph.Registry.get('key-element');
if (key) {
// Log the details of the object to the console
console.log(key);
}
};
Using interactive keys on your charts
Note:
The interactive key will use standard canvas text for the key
- not dom text. You can enable textAccessible if you want but
the interactive key will ignore it.
Formerly the interactive key was only implemented for the Line chart and Pie chart.
As of mid-2013, however, it was
rewritten and is now available with a lot more chart types. The
demo pages for the interactive key are available in
the download archive.
Having been rewritten
the interactive key now uses the drawing api
Rect object and the dynamic library:
Since version 6.12 you've been able to use
formatting macros in your key labels. For example you might
want the value as a part of your key labels and this is an
easy way to do it. To use the macros you can change your
array of key labels to a single string like
this:
%{index}
This gets replaced with the index of the relevant
key item.
%{property:title}
This macro fetches single value properties like the
title property (ie strings or numbers).
%{property:xaxisLabels[%{index}]}
With this macro, you can fetch corresponding values from
arrays - such as the
xaxisLabels property. As shown here, you can
combine this macro
with the %{index} macro to fetch the
relevant value.
%{global:foo.bar.myGlobal}
%{global:foo.bar.myGlobal[%{index}]}
This macro gives you access to global variables - both
strings/numbers and also arrays.
%{value}
%{value_formatted}
With these macros, you can add the value of the
data-point to your key. The
%{value_formatted} property gives you a
formatted value instead of the raw number. For example
instead of 1575886.2 you could get this:
$1,575,886.20c.
The properties to control the formatting are shown
below.
Name: keyFormattedPoint
Description:
This character is used as the decimal point.
Default: .
Name: keyFormattedThousand
Description:
This character is used as the thousand separator.
Default: ,
Name: keyFormattedDecimals
Description:
This specifies the number of decimals that are shown.
Default: 0
Name: keyFormattedUnitsPre
Description:
These units are prepended to the number.
Default: [an empty string]
Name: keyFormattedUnitsPost
Description:
These units are appended to the number.
Default: [an empty string]
%{function:getKeyLabel(%{index})}
This option allows you to call a function that formats
and returns the desired text. When
the template macros are parsed by RGraph this is
parsed last so you can use other macros in the
arguments, as shown, and they end up looking like
this:
%{function:getValue(3)}
So those values get passed to the function and you can
use them to generate and return the
correct value. The return value is then used as the
resultant string.
Note
An RGraph Registry variable
is available to the function for you to get hold of
the chart object and you can get that like
this:
var obj = RGraph.Registry.get('key-label-templates-function-object');
HTML keys
In December 2013 a function was added to RGraph that allows you to use an HTML key next to your chart. This key is made up
of div and span tags so you may find it easier to interact with.
You can read more about HTML keys on this page.