An SVG Line chart with a basic look and feel

Here is a simple Line chart that has three seperate datasets. The labels for the chart (on the X axis) is not a scale - it's just regular labels as you would normally give to a Line chart but they're numbers instead of words - that's all. The Line chart doesn't have the facility to show a scale across the X axis - for that you'll need to use the Scatter chart with the line option enabled.

As for the tickmarks, while at first glance it may appear that they're 'hollow' they're actually just using a fill colour that matches the background.

Other than this is a pretty basic dark-themed Line chart that uses the trace() effect.

This goes in the documents header:
<script src="RGraph.svg.common.core.js"></script>
<script src="RGraph.svg.line.js"></script>
Put this where you want the chart to show up:
<div id="cc" style="width:700px; height: 300px"></div>
This is the code that generates the chart:
<script>
    var line = new RGraph.SVG.Line({
        id: 'cc',
        data: [
            [9,9,0,9,0],
            [6,7,10,5,0],
            [9,4,0,3,4]
        ],
        options: {
            colors: ['#cc0','blue','red'],
            xaxis: false,
            yaxis: false,
            linewidth: 3,
            backgroundGridColor: '#999',
            xaxisLabels: ['5.0','6.0','7.0','8.0','9.0'],
            textColor: '#ccc',
            tickmarksStyle: 'circle',
            tickmarksFill: 'black',
            tickmarksLinewidth: 3
        }
    }).trace();
</script>

How to get transparent tickmarks using the canvas Line chart

[No canvas support] [No canvas support]

You may have noticed that on the chart above the center of the tickmarks are not transparent - they're just colored black in order to make them blend in with the rest of the chart.

Making them transparent is more complicated than you might think for these reasons:

The solution here is to use layers. "But wait! Canvas doesn't have layers!" you might cry. And yes - you would be correct - but they can be simulated by using - in this case - multiple canvas tags.

So there's two canvas tags being utilised here (positioned one in front of the other) - one on to which the background is drawn and a second on to which the lines are drawn. When the inside of the tickmarks are cleared to transparency then the canvas at the back shows through. And that is the canvas that has the background grid on it.

There's more code required than a regular chart (as you might imagine) - but as you can see it's not a lot more and no is it complicated. Feel free to copy and paste the code.


This goes in the documents header:
<script src="RGraph.common.core.js"></script>
<script src="RGraph.line.js"></script>
Put this where you want the chart to show up:
<div style="position: relative; background-color: black; width: 750px; height: 250px">
    <canvas id="cvs1" width="750" height="250" style="position: absolute; top: 0; left: 0">[No canvas support]</canvas>
    <canvas id="cvs2" width="750" height="250" style="position: absolute; top: 0; left: 0">[No canvas support]</canvas>
</div>
Th is is the code that generates the chart:
<script>
    var line1 = new RGraph.Line({
        id: 'cvs1',
        data: [null,null,null,null,null],
        options: {
            noxaxis: true,
            noyaxis: true,
            backgroundGridColor: '#999',
            sbackgroundGridVlines: false,
            sbackgroundGridBorder: false,
            ylabels: false
        }
    }).draw();

    var line2 = new RGraph.Line({
        id: 'cvs2',
        data: [
            [9,9,0,9,0],
            [6,7,10,5,0],
            [9,4,0,3,4]
        ],
        options: {
            colors: ['#cc0','blue','red'],
            noxaxis: true,
            noyaxis: true,
            linewidth: 3,
            backgroundGrid: false,
            labels: ['5.0','6.0','7.0','8.0','9.0'],
            textColor: '#ccc',
            tickmarks: function (obj, data, value, index, x, y, color, prevX, prevY)
            {          
                // Draw the fill of the tickmark. Because the
                // globalCompositeoperation is set to destination-out this
                // actually clears what is drawn instead of drawing it on the
                // canvas
                RGraph.path2(obj.context,
                    'gco destination-out b a % % % 0 6.29 false f red s % gco source-over',
                    x,
                    y,
                    obj.get('ticksize') - 1,
                    color
                );
                
                // This bit draws the ourline of the tickmark. It just draws
                // the stroke because we don't want the center to be overwritten.
                RGraph.path2(obj.context,
                    'b lw 2 a % % % 0 6.29 false s %',
                    x,
                    y,
                    obj.get('ticksize'),
                    color
                );
            },
            ticksize: 6
        }
    }).draw();
</script>