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 show charts on your website.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

 

Download
Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

A black and purple combined chart

[No canvas support]

This demo is an example of a combined Bar and Line. In this case, the Line is a spline but it doesn't have to be. In fact there's a button beneath the chart that you can use to toggle whether it's a spline (curvy) or a regular angular Line. All this button does is toggle the spline setting and then redraw the canvas.

In RGraph, combining a Bar chart and a Line chart is made easy by the CombinedChart class. You can see this being used in the code below. It simply takes the Bar and the Line objects and sets the correct settings on them and then draws the chart. But normally you would want only one set of labels (ie the Bar or the Line) drawn, however here the Bar charts labels are on one side and the Line chart labels are on the other. So after the combo class has been drawn, the y-axis labels are turned back on for the Line chart object and everything is redrawn. You can see how this is done in the code below.

The CombinedChart class is freely usable by you in a very similar way to the other RGraph classes. It's created in the same way and you pass it an array of objects - which usually is a combination of Bar and Line objects. You can give it more types if you want.

Apart from this, the chart has "larger than the default" text and the Bar uses a gradient for the fill color: Gradient(#A18AC5:#D1AAF5)

The responsive function reduces the size of the chart, the size of the text on the chart and the margins. The function is added to both the Bar and the Line chart and the Line chart version also reduces its linewidth.


This goes in the documents header:
<script src="RGraph.common.core.js"></script>
<script src="RGraph.bar.js"></script>
<script src="RGraph.line.js"></script>
Put this where you want the chart to show up:
<div style="float: right; display: inline-block; margin: 25px">
    <canvas id="cvs" width="750" height="250" style="background-color: #555; border: 5px solid black; border-radius: 7px; box-shadow: 2px 2px 3px gray">[No canvas support]</canvas><br />
    <button style="border-radius: 5px; font-size: 20px; margin: 10px; padding: 7px" onclick="line.set('spline', !line.get('spline')); RGraph.redraw()">Toggle spline</button>
</div>
This is the code that generates the chart - it should be placed AFTER the canvas tag(s):
<script>
    bar = new RGraph.Bar({
        id: 'cvs',
        data: [81,90,75,85,90,78,61],
        options: {
            yaxisScaleMax: 100,
            backgroundGridVlines: false,
            backgroundGridBorder: false,
            backgroundGridColor: '#999',
            xaxisLabels: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
            marginLeft: 55,
            marginRight: 55,
            marginBottom: 45,
            colors: ['Gradient(#A18AC5:#D1AAF5)'],
            textColor: '#ccc',
            xaxisTickmarksCount: 0,
            xaxis: false,
            yaxis: false,
            shadowColor: 'black',
            shadowOffsetx: 0,
            shadowOffsety: 0,
            shadowBlur: 15,
            colorsStroke: 'rgba(0,0,0,0)',
            combinedEffect: 'wave',
            combinedEffectOptions: '{frames: 30}',
            responsive: [
                {maxWidth: null,width:600,height:250,options:{textSize:18,marginInner: 20}},
                {maxWidth: 900, width:400,height:200,options:{textSize:12,marginInner: 7}}
            ]
        }
    });



    line = new RGraph.Line({
        id: 'cvs',
        data: [150,255,566,542,588,122,131],
        options: {
            yaxisScaleMax: 600,
            xaxis: false,
            yaxis: false,
            backgroundGrid: false,
            colors: ['#d00'],
            yaxisPosition: 'right',
            textColor: '#ccc',
            marginLeft: 45,
            marginRight: 45,
            tickmarksStyle: null,
            spline: true,
            combinedEffect: 'trace',
            textSize: 18,
            responsive: [
                {maxWidth: null,options:{textSize:18,marginInner: 45,linewidth: 7}},
                {maxWidth: 900, options:{textSize:12,marginInner: 20,linewidth: 5}}
            ]
        }
    });
    
    combo = new RGraph.CombinedChart([bar, line])
        .draw();
    
    // Because the combo class turns the Line chart labels off,
    // turn them back on
    line.set({
        yaxisScale: true
    });

    RGraph.redraw();
</script>