About
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
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...
New HTML datagrid
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.
Download
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.
License
RGraph can be used for free under the GPL or if
that doesn't suit your situation there's an
inexpensive (£129) commercial license available.The drawing API Y-axis object API reference
The y-axis object allows you to have extra Y axes in your chart. Formerly this was an independent function but it's now been converted to a drawing api object. This means that it's easier to use and has added interactivity options - such as mousemove and click events and tooltips.
Usage example
See all of the 1200+ demos in the download archive.
<script>
bar = new RGraph.Bar({
id: 'cvs',
data: [[1,2,8],[3,8,7],[9,6,5],[3,5,8],[5,6,6],[1,5,8],[4,8,6]],
options: {
backgroundGridVlines: false,
backgroundGridBorder: false,
marginInner: 5,
xaxis: false,
yaxis: false,
xaxisLabels: ['Mar','Apr','May','Jun','Jul','Aug','Sep'],
yaxisScale: false,
marginLeft: 195,
marginTop: 35,
colors: [
'Gradient(green:#0c0)',
'Gradient(red:#c00)',
'Gradient(blue:#00c)'
],
tooltips: [
'James','Jenna','Karl',
'James','Jenna','Karl',
'James','Jenna','Karl',
'James','Jenna','Karl',
'James','Jenna','Karl',
'James','Jenna','Karl',
'James','Jenna','Karl'
],
key: ['James','Jenna','Karl'],
keyPosition: 'margin',
marginInner: 10,
textSize: 16
}
}).wave();
new RGraph.Drawing.YAxis({
id: 'cvs',
x: bar.marginLeft,
options: {
marginTop: 35,
yaxisScaleMax: bar.scale2.max * 2,
yaxisScaleDecimals: 1,
textColor: 'blue',
textSize: 16,
yaxisColor: ['blue'],
tooltips: 'Moisture measured by the MET office',
tooltipsCss: {
backgroundColor: 'black',
color: 'white'
}
}
}).draw();
new RGraph.Drawing.YAxis({
id: 'cvs',
x: bar.marginLeft - 70,
options: {
marginTop: 35,
yaxisScaleMax: bar.scale2.max * 5,
yaxisScaleDecimals: 1,
textColor: 'red',
textSize: 16,
yaxisColor: ['red'],
tooltips: 'Sunshine measured by the MET office',
tooltipsCss: {
backgroundColor: 'black',
color: 'white'
}
}
}).draw();
new RGraph.Drawing.YAxis({
id: 'cvs',
x: bar.marginLeft - 140,
options: {
marginTop: 35,
yaxisScaleMax: bar.scale2.max,
yaxisScaleDecimals: 1,
tooltips: ['Rainfall measured by the MET office'],
tooltipsCss: {
backgroundColor: 'black',
color: 'white'
},
yaxisColor: ['green'],
textColor: 'green',
textSize: 16
}
}).draw();
</script>
Properties
- Y-axis properties
- Margin properties
- Other label properties
- Interactive features properties
- Miscellaneous properties
Y-axis properties
Name: yaxisTickmarksCount
Description:
This allows you to stipulate how many y-axis tickmarks there are.
Default: null (related to how many labels there are)
Name: yaxisTickmarksLastTop
Description:
Whether the top-most tickmark is drawn.
Default: null (displayed if the x-axis position warrants it)
Name: yaxisTickmarksLastBottom
Description:
Whether the bottom-most tickmark is drawn.
Default: null (displayed if the x-axis position warrants it)
Name: yaxisLabelsCount
Description:
A value that controls how many Y labels there are. This value could formerly be either 1/3/5/10 however now it can be any number.
Default: 5
Name: yaxisLabelsSpecific
Description:
You can use this option to give your own Y labels (eg ['Low', 'Medium', 'High']. Note: Since March 2013 you may now need to add an extra (optionally) empty element to the array of labels to achieve your desired result.
Default: null
Name: yaxisLabelsPosition
Description:
This controls how the specific labels are positioned on the y-axis. It has no effect on a scale.
Default: edge
Name: yaxisLabelsOffsetx
Description:
This allows you finer-grained control in the horizontal direction over the Y label positioning if you need it.
Default: 0
Name: yaxisLabelsOffsety
Description:
This allows you finer-grained control in the vertical direction over the Y label positioning if you need it.
Default: 0
Name: yaxisLabelsClass
Description:
This property allows you to add your own CSS class to the y-axis labels which you can then use for styling purposes or to make retrieving the span tags easier (the dom elements). If you inspect the labels in your browser's javascript console (you will first need to enable the textAccessiblePointerevents property) you will be able to see the other CSS classes that are assigned to the labels.
Default: [none]
Name: yaxisTitleSize
Description:
This allows you to specify a size for the y-axis title.
Default: null
Name: yaxisTitleFont
Description:
This allows you to specify a font for the y-axis title.
Default: null
Name: yaxisTitleBold
Description:
This controls whether the y-axis title is bold or not.
Default: null
Name: yaxisTitleItalic
Description:
This controls whether the y-axis title is italic or not.
Default: null
Name: yaxisTitlePos
Description:
This is multiplied with the margin to give the position of the y-axis title.
Default: 0.25
Name: yaxisTitleOffsetx
Description:
The pixel offset that's added to the y-axis titles X coordinate.
Default: 0
Name: yaxisTitleOffsety
Description:
The pixel offset that's added to the y-axis titles Y coordinate.
Default: 0
Name: yaxisTitleX
Description:
By giving this you can specifically set the X position of the y-axis title.
Default: null
Name: yaxisTitleY
Description:
By giving this you can specifically set the Y position of the y-axis title.
Default: null
Name: yaxisScaleUnitsPre
Description:
The units that the y-axis is measured in. This string is displayed before the actual number, allowing you to specify values such as "$50".
Default: none
Name: yaxisScaleUnitsPost
Description:
The units that the y-axis is measured in. This string is displayed after the actual number, allowing you to specify values such as "50ms".
Default: none
Name: yaxisScaleMax
Description:
The optional maximum Y scale value. If not specified then it will be calculated.
Default: null (It's calculated)
Name: yaxisScaleMin
Description:
The optional minimum Y scale value. If not specified then it will be 0.
Default: 0
Name: yaxisScaleFormatter
Description:
To allow thoroughly custom formats of numbers in the scale, you can use this option to specify a function that is used by RGraph to format numbers. This function should handle ALL of the formatting. Eg:
function myFormatter(opt)
{
var num = Number(opt.number) * 5;
return String(num)
}
obj.set('yaxisScaleFormatter', myFormatter);Default: null
Name: yaxisScaleRound
Description:
Whether to round the scale up. eg A maximum value of 59 results in scale to 100.
Default: false
Margin properties
Name: marginTop
Description:
The top margin of the axis. This can be the same or different to the chart.
Default: 35
Other label properties
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: 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
Interactive features properties
Name: tooltips
Description:
This can be an array of tooltips (only the first element is used) that are shown when the axis is clicked on.
Default: null
Name: tooltipsEvent
Description:
This is the event that triggers the tooltips. It can be either click or mousemove.
Default: click
Name: tooltipsEffect
Description:
The effect used for showing tooltips. Can be either fade or none.
Default: fade
Name: tooltipsCssClass
Description:
This is the name of the CSS class the chart uses.
Default: RGraph_tooltip
Name: tooltipsOverride
Description:
If you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.
Default: null
Name: tooltipsPersistent
Description:
If you want the tooltips to persist after a click (ie they don't disappear) then you can set this property to true to get this behaviour. Keep in mind that if you have a lot of bars/segments/points/etc then it's possible for the chart to become quite crowded. If you need to subsequently clear all of the tooltips there's an api function available to do that for you and it's called: RGraph.tooltip.persistent.clear() If you want to access any (or all) of the tooltip div tags then you can do so using the RGraph.tooltip.persistent object. This option works when you have the tooltipsEvent property set to mousemove
Default: false
Name: tooltipsNohideonclear
Description:
Not an option that you'll need particularly often, if at all. Setting this to true means that when you call the RGraph.clear api function the tooltip DOES NOT get hidden.
Default: false
Name: tooltipsFormattedPoint
Description:
When using formatted tooltip strings this is used as the point when using the %{value_formatted} option.
Default: .
Name: tooltipsFormattedThousand
Description:
When using formatted tooltip strings this is used as the thousand separator when using the %{value_formatted} option.
Default: ,
Name: tooltipsFormattedDecimals
Description:
When using formatted tooltip strings this specifies the number of decimals when using the %{value_formatted} option.
Default: 0
Name: tooltipsFormattedUnitsPre
Description:
When using formatted tooltip strings these units are prepended to the number when using the %{value_formatted} option.
Default: (an empty string)
Name: tooltipsFormattedUnitsPost
Description:
When using formatted tooltip strings these units are appended to the number when using the %{value_formatted} option.
Default: (an empty string)
Name: tooltipsFormattedListType
Description:
With this property you can switch between an unordered list (the default) and an ordered list. Possible values are ul and ol.
Default: ul
Name: tooltipsFormattedListItems
Description:
This should be a two-dimensional array of the list items that are to be shown for all of the tooltips. An example of this property is:
tooltipsFormattedListItems: [
['Bill','Jerry','Berty'],// First tooltip
['Gill','Carrie','Lucy'],// Second tooltip
['Pob','Nobby','Hilda'] // Third tooltip
]
You can use CSS to style this list - for example:
.RGraph_tooltip ul#rgraph_formatted_tooltips_list li {
text-align: left;
color: yellow;
}
Default: null
Name: tooltipsFormattedTableHeaders
Description:
When showing a table in the tooltips this can be an array of headers for the table. These are added to the tooltip using th tags.
Default: null
Name: tooltipsFormattedTableData
Description:
This is the data that is added to the table. This is a 3-dimensional array so it's easy to make a mistake. See the example, copy the code from it and then modify it suit. You'll create fewer bugs this way.
Default: null)
Name: tooltipsPointer
Description:
By default the tooltips have a small triangular pointer that points to the shape that was clicked on. You can turn this off with this property.
Default: true
Name: tooltipsPointerCss
Description:
If you want any CSS values applied to the tooltips pointer (a CSS border, for example) then specify an object containing those values to this property. For example:
tooltips: {
borderLeft: 'gray 2px solid',
borderBottom: 'gray 2px solid'
}Default: null
Name: tooltipsPointerOffsetx
Description:
This allows you to adjust the vertical position of the tooltips pointer.
Default: 0
Name: tooltipsPointerOffsety
Description:
This allows you to adjust the vertical position of the tooltips pointer (for example, if you add a border you may need to move it down slightly).
Default: 0
Name: tooltipsPositionStatic
Description:
The new default (as of August 2020) is for tooltips to be positioned statically and not be dependent on the mouse position. If you don't want this for whatever reason, you can disable it with this setting. When you set it to false tooltips are positioned next to the mouse pointer.
Default: true
Name: tooltipsCss
Description:
If you want to specify some CSS that gets applied to all of the tooltips, but don't want to use the RGraph.tooltips.style object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object CSS for the tooltips. These are CSS styles that get applied to all of the tooltips for the specific object only. It should look like this:
tooltipsCss: {
fontFamily: 'Verdana',
fontSize: '20pt'
}Default: null
Miscellaneous properties
Name: highlightStyle
Description:
By default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument.
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:
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 listener)
Description:
This method adds an event listener (such as beforedraw or draw) to the 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 listener function. For example:
obj.on('draw', function (obj)
{
// Put your code here
});
var obj = new RGraph.Drawing.YAxis({
id: 'cvs',
x: 35,
}).on('draw', function (obj)
{
// Put your draw event code here
}).on('click', function (e, shape)
{
// Handle the click event
}).draw();
You can also use the new (added in version 6.22) events property to add events and that looks like this:
<script>
new RGraph.Drawing.YAxis({
id: 'cvs',
x: 35,
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.redraw function. Because this function only runs once the RGraph.redraw function would not cause a loop - which would happen if you used the draw event.
obj.exec(function (obj)
{
// Put your code here
});
Name: object getShape(object event)
Description:
This method makes it easy to get hold of the Y-axis
object when it has been clicked on or hovered over.
It returns an object which has the following indexes
available:
| object | The Y-axis object. |
| x | The X coordinate of the Y-axis. |
| y | The Y coordinate of the Y-axis. |
| width | The width of the Y-axis (this includes the label area). |
| height | The height of the Y-axis. |
| dataset | As there's only ever one element this is always zero. |
| index | As there's only ever one element this is always zero. |
| sequentialIndex | As there's only ever one element this is always zero. |
| tooltip | If a tooltip is associated with the Y-axis object this will be it. id: strings are expanded for you (where the tooltip text is retrieved from the HTML tag with the matching ID). |
<script>
yaxis.canvas.onclick = function (e)
{
RGraph.redraw();
var canvas = e.target,
obj = canvas.__object__,
shape = obj.getShape(e);
if (shape) {
// Highlight the Y-axis object.
obj.path(
'lw 10 b r % % % % s black f rgba(255,0,0,0.25)',
shape.x, shape.y, shape.width, shape.height
);
}
}
</script>
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.Drawing.YAxis({
id: 'cvs',
x: 35,
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();