About
RGraph is a JavaScript charts library based on
HTML5 SVG and canvas. RGraph is mature (over 15 years
old) and has a wealth of features making it an ideal
choice to use for showing charts on your website.
Download
Get the latest version of RGraph (version 6.18, 1st June 2024) 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.A Bar chart using AJAX
Here is an example of a 3D variation of the Bar chart
which is both animated using the
grow
effect and which is also fetching its data via ajax
.
The ajax
script is a simple one that just outputs a sequence of random numbers.
You can see the script directly by going here.
If you view the ajax
script you'll see that it just outputs the numbers and nothing
else - so no labels or title. So on the chart, the labels are just hardcoded.
The rest of the configuration is pretty straightforward - and you can see it below.
When the screen is smaller the canvas
dimensions are reduced, the marginInner
is
reduced and the textSize
is reduced as well.
<script src="RGraph.common.core.js"></script> <script src="RGraph.common.dynamic.js"></script> <script src="RGraph.common.tooltips.js"></script> <script src="RGraph.bar.js"></script>Put this where you want the chart to show up:
<div style="float: right"> <canvas id="cvs" 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> // Use the RGraph.AJAX.getCSV() function to fetch some CSV data from the server. // This example fetches the URL https://www.rgraph.net/getdata.html which just // outputs a set of CSV values. The second argument is a function which is // used as the callback and creates the chart. RGraph.AJAX.getCSV('/getdata.html', function (data) { new RGraph.Bar({ id: 'cvs', // Use the CSV data directly in the chart configuration data: data, options: { colors: ['gradient(#080:green)'], xaxisLabels: ['John', 'Fred', 'Joe', 'Rich', 'Pete', 'Lilly', 'Fred', 'Joe', 'Rich', 'Pete'], marginLeft: 35, // This sets it so that the bar chart is drawn as a 3D variant variant: '3d', // 3D Bar charts look better with a transparent stroke color colorsStroke: 'transparent', marginInnerGrouped: true, backgroundGridVlines: false, backgroundGridBorder: false, shadowOffsetx: 10, marginBottom: 75, xaxis: false, yaxis: false, tooltips: '<span style="font-size: 14pt">Total value:<br /><span style="font-size: 26pt">%{value}%', title: 'An animated 3D Bar chart', titleColor: '#666', titleBold: true, titleSize: 16, titleOffsety: 5, titleSubtitle: 'This chart uses random data', titleSubtitleOffsety: -5, responsive: [ {maxWidth: null,width:600,height:250,options:{marginInner: 10,textSize:12},parentCss:{'float': 'right',textAlign:'none'}}, {maxWidth: 800,width:400,height:200,options:{marginInner: 5,textSize:10},parentCss:{'float': 'none',textAlign:'center'}} ] } // The grow() animation effect is used and works just like a regular Bar chart. Some // responsive capability is also added. }).grow(); }); </script>