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.
New datagrid in v6.21
In version 6.21 a new datagrid object has been 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 6.21, 10th April 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 Marker3 object API reference
Usage example
<script> line = new RGraph.Line({ id: 'cvs', data: [4,9,1,3,2,6,5], options: { spline: true, backgroundGridVlines:false, backgroundGridBorder:false, xaxis: false, yaxis: false, xaxisLabels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'], marginInner: 5, tickmarksStyle: 'endcircle', tickmarksSize: 10, colors: ['black'], textSize: 16 } }).draw(); x = line.coords[2][0]; y = line.coords[2][1]; radius = 25; marker3 = new RGraph.Drawing.Marker3({ id: 'cvs', x: x, y: y, radius: radius, options: { colorsFill: 'green' } }).draw(); </script>
Properties
Color properties
Other text 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
Miscellaneous properties
Methods
obj.get(name)
An accessor that you can use to retrieve the values of properties.
obj.set(name, value)
An accessor that you can use to set the values of properties.
obj.getShape(event)
This method makes it easy to get hold of the marker when it has been clicked on or hovered over. It returns an object which has the following indexes available:
object |
The chart object. |
x |
The center X coordinate of the marker. |
y |
The center Y coordinate of the marker. |
radius |
The radius of the marker. |
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 Marker3 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).
|
canvas
is redrawn.
<script> marker3.onclick = function (e, shape) { marker3.on('draw', function (obj) { obj.path( 'lw 10 b a % % % 0 6.29 false s black f red', shape.x, shape.y, shape.radius ); }); } </script>
obj.on(event, function)
This method can be used to set an event listener on an 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 handler function. For example:
obj.on('draw', function (obj)
{
// Put your event code here
});
The function is useful if you use method chaining when creating your charts:
obj = new RGraph.Drawing.Marker3({ id: 'cvs', }).on('draw', function (obj) { // Put your draw event code here }).on('click', function (e, shape) { // Handle the click event }).draw();
obj.exec(function)