About
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
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.
Download
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.
Latest forum posts
These are the latest support forum posts that have been
posted or updated.
9th June, Richard
New version of RGraph: version 7.20
3rd June, Patrick
Question about installing RGraph
1st June, Ouja
How do I add a click event to a bar in my Bar chart?
8th May, Anthony Kuma
Does the SVG Line chart have outofbounds functionality?
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.A switch animation effect
It's a nice transition effect where one chart blends into another with a "folding-away" type motion. The other chart is shown in the reverse direction. The effect is not animated by using javascript animation but by using javascript to apply css properties. The css transitions that are also specified on the canvas then take care of doing the animating.
The charts themselves are quite straightforward - with the Line chart having a larger linewidth and bigger tickmarks than normal.
This goes in the documents header:
<script src="RGraph.common.core.js"></script>
<script src="RGraph.line.js"></script>
<script src="RGraph.bar.js"></script>
<style>
div#canvas-container {
position: relative;
width: 600px;
height: 250px;
}
div#canvas-container canvas {
position: absolute;
top: 0;
left: 0;
width: 600px;
height: 250px;
background-color: white;
transition: all 1s;
opacity: 1;
}
div#canvas-container canvas#cvs1 {
top: 125px;
left: 300px;
width: 0;
height: 0;
opacity: 0;
transform: rotate(90deg);
}
</style>
Put this where you want the chart to show up:
<div id="canvas-container" style="display: inline-block; float: right">
<canvas id="cvs1" width="600" height="250">[No canvas support]</canvas>
<canvas id="cvs2" width="600" height="250">[No canvas support]</canvas>
</div>
This is the code that generates the chart - it should be placed AFTER the canvas tag(s):
<script>
// First create the Bar chart but don't call the draw() function.
bar = new RGraph.Bar({
id: 'cvs1',
data: [4,8,12],
options: {
colors: ['#5690C9'],
marginInner: 25,
textSize: 16,
titleSize: 12,
title: 'A Bar chart (click to switch to the Line chart)',
xaxisLabels: ['John','Fred','Lucy']
}
}).draw();
bar.canvas.style.width = 0;
bar.canvas.style.height = 0;
bar.canvas.style.left = '300px';
bar.canvas.style.top = '125px';
// Create the Line chart with no X-axis
line = new RGraph.Line({
id: 'cvs2',
data: [
[1,6,4],
[5,3,8]
],
options: {
colors: ['#B71A1A','#54A4CF'],
tickmarksStyle: 'filledcircle',
tickmarksSize: 10,
linewidth: 10,
xaxisLabels: ['John','Fred','Lucy'],
title: 'A Line chart (click to switch)',
marginInner: 25,
marginTop: 50,
textSize: 16,
textColor: 'black',
titleSize: 24
}
}).draw();
// This is the click event handler that swaps the canvas
// tag width/height/opacity CSS properties.
document.getElementById('cvs1').onclick =
document.getElementById('cvs2').onclick = function (e)
{
var id = e.target.id;
var el1 = document.getElementById('cvs1');
var el2 = document.getElementById('cvs2');
// If the canvas that was clicked on was cvs1 then do this
// (hide cvs1 and show cvs2)
if (id === 'cvs1') {
el1.style.width = 0;
el1.style.height = 0;
el1.style.top = '125px';
el1.style.left = '300px';
el1.style.opacity = 0;
el1.style.transform = 'rotate(180deg)';
el2.style.width = '600px';
el2.style.height = '250px';
el2.style.top = 0;
el2.style.left = 0;
el2.style.opacity = 1;
el2.style.transform = 'rotate(0)';
// If the canvas that was clicked on was cvs2 then do
// this (hide cvs2 and show cvs1)
} else {
el2.style.width = 0;
el2.style.height = 0;
el2.style.top = '125px';
el2.style.left = '300px';
el2.style.opacity = 0;
el2.style.transform = 'rotate(180deg)';
el1.style.width = '600px';
el1.style.height = '250px';
el1.style.top = 0;
el1.style.left = 0;
el1.style.opacity = 1;
el1.style.transform = 'rotate(0)';
}
};
</script>