MENU
.net Powerful JavaScript charts
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.

More »

 

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 »

 

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.

Download »

 

Latest forum posts
These are the latest support forum posts that have been posted or updated.


16th June, Rachel
I have a question about the 3D Bar chart
12th June, Marco
Should I use SVG or canvas for the charts on my website?
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?


Support forum »

 

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.

More »

New demo of combined Bar and Line chart with left alignment

Written by Richard Heyes, RGraph author, on 17th September 2024

A recent support request asked for this - a combined Bar and Line chart with one key difference - the Line chart points are left-aligned in each little section instead of being center-aligned. You can see what is meant by this on the chart below.

[No canvas support]

The first thing that's done by the code is create the Bar chart and Line chart.

<script>
    // Here's the data for both the Bar chart and
    // also the Line chart
    data1 = [4,8,6,3,5,5,8];
    data2 = [8,6,4,3,9,8,7];

    //
    // Create and configure the Bar chart using
    // the data above. Crucially - don't call
    // the draw() function at the end. This will
    // be done by the CombinedChart object that
    // we create.
    //
    bar = new RGraph.Bar({
        id: 'cvs',
        data: data1,
        options: {
            marginInner: 20,
            marginInnerGrouped: 5,
            xaxisLabels: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
            textSize: 20
        }
    });
    //
    // Create and configure the Line chart using
    // the data from above. Again, - don't call
    // the draw() function at the end. The
    // CombinedChart object that we create will
    // do this.
    //
    line = new RGraph.Line({
        id: 'cvs',
        data: data2,
        options: {
            colors: ['black'],
            spline: true,
            linewidth: 2,
            tickmarksStyle: 'filledendcircle',
            tickmarksSize: 5
        }
    });
    

    // 
    //  Create the CombinedChart object that draws
    // the two objects on to the canvas.
    // 
    new RGraph.CombinedChart(bar, line).draw();
</script>

So that code creates a regular, combined Bar and Line chart where the Line chart points are centered within each bar. This is normally what you would want and expect to see. But now we're going to left align the Line chart points. It's very easy to do and just requires you to change the marginLeft and marginRight properties - essentially just shifting the Line chart left. You could calculate the exact pixel value that you should use with the marginLeft and marginRight settings if you wanted to - and you might particularly want to do this if you're using the responsive property to support multiple screen sizes (if you're doing this you'll probably need to use the responsive callback to update the new margins that should be used when the screen size changes)

<script>
    // 
    // Move the Line chart left so its points are left
    // aligned with the bars (now that the CombinedChart
    // object has done its thing). This could be calculated
    // from the Bar chart coordinates but here it's just an
    // approximate value.
    // 
    line.set('marginLeft', 30);  //  Decrease this
    line.set('marginRight', 110); //  Increase this
    
    // Redraw the canvas so that the Line chart will
    // now use the updated margin sizes.
    RGraph.redraw();
</script>