The drawing API

Recommend RGraph:  
    Read comments...

Summary
The drawing API can be used to add extra information and/or interactivity to your charts.

[No canvas support]

The RGraph Drawing API is a new addition in September 2012 and allows you to add shapes to your charts. These shapes allow you to extend the interactivity of and information on your charts by adding shapes to them. The shapes have a very similar structure to a chart library - you create and manipulate them in the same way. As well as this they support similar interactive properties - such as tooltips, events.click and events.mousemove. This makes them very useful for providing your users with extra information - much like tooltips do by themselves - and also highlighting areas on the chart.

The source to create the chart shown is provided below.

<script>
    var line = new RGraph.Line({
        id: 'cvs',
        data: [4,9,1,3,2,6,5],
        options: {
            labels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
            hmargin: 5,
            tickmarks: 'endcircle',
            gutterTop: 35,
            colors: ['black']
        }
    }).draw();
    
    var marker1 = new RGraph.Drawing.Marker1({
        id: 'cvs',
        x: line.coords[3][0],
        y: line.coords[3][1],
        radius: 15,
        text: 'W',
        options: {
            tooltips: [
                '<b>Winner!</b><br />Mark sold by far the most' +
                'widgets and as a result is the winner!'
            ],
            highlightFill: 'rgba(255,0,0,0.7)'
        }
    }).draw();
    
    var circle = new RGraph.Drawing.Circle({
        id: 'cvs',
        x: line.coords[2][0],
        y: line.coords[2][1], 15,
        radius: 20,
        options: {
            strokestyle: 'black',
            fillstyle: 'rgba(255,0,0,0.7)'
        }
    }).on('click', function (e, shape)
    {
        alert('[NOTICE] Also worthy of note is the low point of the competition - which was wednesday')
    }).on('mousemove', function (e, shape)
    {
        e.target.style.cursor = 'pointer';
    }).draw();


    var image = new RGraph.Drawing.Image({
        id: 'cvs',
        x: line.get('gutter.left') + 5,
        y: line.canvas.height - line.get('gutter.bottom') - 5,
        src: '/images/logo.png',
        options: {
            valign: 'bottom',
            tooltips: [
                '<b>Information</b><br />The image drawing object could be ' +
                'used as a method of<br />' +
                'providing more information to your users.'
            ],
            tooltipsEvent: 'onclick'
        }
    }).draw();
</script>

Comments