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 »

 

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 »

 

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 »

A 3D Line chart demonstration

Written by Richard Heyes, RGraph author, on 13th June 2021

Here's a novel new demonstration of a chart: A 3D Line chart with multiple datasets. This is not a natively supported type of chart though the code to create it, whilst big, is not complicated and it's fully annotated so you should find it easy to follow.

The next release will feature it as part of the demos that come with RGraph which are located in the demos/ folder and it will be called: demos/line-chart-3d.html. Here's an image showing it and you can see the demo in its full glory by following the link below to a codepen of it.

<script>
    //
    // Margins for the rear of the chart
    //
    marginLeft    = 90;
    marginRight   = 40;
    marginTop     = 20;
    marginBottom  = 105;
    marginInner   = 5;
    
    //
    // Colors for the lines
    //
    colors = [
        'rgba(255,0,0,0.75)',
        'rgba(0,0,255,0.75)',
        'rgba(0,128,0,0.75)'
    ];
    filledColors = [
        'rgba(255,0,0,0.5)',
        'rgba(100,100,255,0.65)',
        'rgba(0,200,0,0.75)'
    ];
    
    //
    // The line data
    //
    data = [
        [8,9,7,8,10,10,13,12,9,8,9,11,8,11,13,12,11,13,10,8,9,10,8,12,11,9,10,9,8,11],
        [8,7,6,5,6,7,5,6,8,8,8,9,5,6,8,7,5,6,6,8,7,5,6,8,7,8,6,9,9,7],
        [5,6,8,3,6,5,5,4,5,6,6,7,6,5,4,6,7,5,4,5,6,5,5,5,6,8,7,8,6,5]
    ];
    
    //
    // X axis labels
    //
    xaxisLabels = [
        '','','','Week 1','','','',
        '','','','Week 2','','','',
        '','','','Week 3','','','',
        '','','','Week 4','','','',
        '',''
    ];
    
    // The title
    title = 'Amount of sales last month';
    
    // Maximum value for the Y scale
    yaxisScaleMax = 15;
    
    // How much to transform by to get the 3D look
    transformX = -25;
    transformY = 15;
    
    
    
    
    
    
    
    
    // Set the initial transformation on the canvas in order
    // to provide the 3D look
    context = document.getElementById('cvs').getContext('2d');
    context.setTransform(1,0.1,0,1,0,0);
    
    //
    // Draw the "chart" that provides the
    // background grid. The chart is not
    // displayed - it only shows the
    // background grid
    //
    new RGraph.Line({
        id: 'cvs',
        data: [],
        options: {
            // The background grid is only enabled on this chart
            backgroundGridColor: '#ccc',
            backgroundGridHlinesCount: 5,
            backgroundGridVlines: false,
            backgroundGridBorder: false,
            //backgroundGridDashed: false,
            //backgroundGridColor: '#333',
            
            // Set the margins based on the values that are defined above
            marginBottom: marginBottom,
            marginTop:    marginTop,
            marginLeft:   marginLeft,
            marginRight:  marginRight,
            marginInner:  marginInner,
    
            yaxisScaleMax: yaxisScaleMax,
            xaxis: false,
            yaxis: false,
            yaxisPosition: 'right',
            yaxisScaleUnitsPost: 'Kg',
    
            // Use canvas based text that takes the 3D
            // transformation into account
            textAccessible: false,
            textSize: 10,
            title: title,
            titleSize: 16,
            titleBold: true,
            titleOffsety: 5
        }
    }).draw();
    
    
    
    
    
    
    
    
    //
    // Draw the first chart after adjusting
    // the transformation
    //
    context.transform(1,0,0,1,transformX,transformY);
    
    new RGraph.Line({
        id: 'cvs',
        data: data[0],
        options: {
    
            colors: [colors[0]],
            
            shadow: false,
    
            // The background grid is only enabled on this chart - the
            // bar chart at the back
            backgroundGrid: false,
    
            marginBottom: marginBottom,
            marginTop: marginTop,
            marginLeft: marginLeft,
            marginRight: marginRight,
            marginInner: marginInner,
            
            filled: true,
            filledColors: [filledColors[0]],
    
            xaxis: false,
            yaxisScaleMax: yaxisScaleMax,
            yaxis: false,
            yaxisPosition: 'right',
            yaxisScale: false,
            
            linewidth: 5
        }
    }).draw();
    
    
    
    
    
    
    
    
    //
    // Draw the second line chart after adjusting
    // the transformation
    //
    context.transform(1,0,0,1,transformX,transformY);
    
    new RGraph.Line({
        id: 'cvs',
        data: data[1],
        options: {
    
            colors: [colors[1]],
            
            shadow: false,
    
            backgroundGrid: false,
    
            marginBottom: marginBottom,
            marginTop: marginTop,
            marginLeft: marginLeft,
            marginRight: marginRight,
            marginInner: marginInner,
            
            filled: true,
            filledColors: [filledColors[1]],
    
            yaxisScaleMax: yaxisScaleMax,
            xaxis: false,
            yaxis: false,
            yaxisScale: false,
            
            linewidth: 5
        }
    }).draw();
    
    
    
    
    
    
    
    //
    // Draw the third line chart after adjusting
    // the transformation
    //
    context.transform(1,0,0,1,transformX,transformY);
    
    new RGraph.Line({
        id: 'cvs',
        data: data[2],
        options: {
    
            colors: [colors[2]],
            
            shadow: false,
    
            backgroundGrid: false,
    
            marginBottom: marginBottom,
            marginTop: marginTop,
            marginLeft: marginLeft,
            marginRight: marginRight,
            marginInner: marginInner,
            
            filled: true,
            filledColors: [filledColors[2]],
    
            yaxisScaleMax: yaxisScaleMax,
            xaxis: false,
            yaxis: false,
            yaxisScale: false,
            
            // The X axis labels are shown on this chart
            textSize: 10,
            textAccessible: false,
            
            linewidth: 5,
            
            xaxisLabels: xaxisLabels
        }
    }).draw();
</script>