The drawing API background object

Summary: Documentation for the drawing API background object that can be added to your charts and provides a way for you to give your charts a 'manual' background. It's useful when you're manipulating the grid and the built-in background options do not suffice.

[No canvas support]

The background object allows you to add a background to your charts should you need to. An example use might be when you want the background grid to be clickable (ie have a tooltip). In this case you can use the Background drawing API object (and its own margin settings) to make a grid that spans the whole of the desired area.

The Background object can have its own tooltip and also its own click and mousemove events so if you want to make the whole chart area clickable this is one way that you can do that.


Usage example

<script>
    new RGraph.Drawing.Background({
        id: 'cvs',
        options: {
            title: 'The background object',
            marginTop: 55,
            tooltips: ['The drawing API background object'],
            textSize: 18,
            textBold: true
        }
    }).draw();
</script>

Properties

Methods

obj.get(name)
An accessor that you can use to retrieve the values of properties.

obj.set(name, value)
An accessor that you can use to set the values of properties.

obj.getShape(event)
This method makes it easy to get hold of the background when it has been clicked on or hovered over. It returns an object which has the following indexes available:
object The chart object.
dataset As there's only ever one element this is always zero.
index As there's only ever one element this is always zero.
sequentialIndex As there's only ever one element this is always zero.
tooltip If a tooltip is associated with the Background object this will be it.id: strings are expanded for you (where the tooltip text is retrieved from the HTML tag with the matching ID).
<script>
    background.canvas.onclick = function (e)
    {
        RGraph.redraw();
    
        var canvas = e.target,
            obj    = canvas.__object__,
            shape  = obj.getShape(e),
            prop   = obj.properties,
            width  = canvas.width - prop.marginLeft - prop.marginRight,
            height = canvas.height - prop.marginTop - prop.marginBottom;

        if (shape) {            
            // Highlight the main body of the Background object.
            RGraph.path({
                object: obj,
                  path: 'lw 10 b r % % % % s black f rgba(255,0,0,0.25)',
                  args: [prop.marginLeft, prop.marginTop, width, height]
            });
        }
    }
</script>

obj.on(event, function)

This method can be used to set an event listener on an object. It operates in a similar way to the jQuery on() function. The first argument is the event that you wish to attach to and the second is the handler function. For example:

obj.on('draw', function (obj)
{
    // Put your event code here
});

The function is useful if you use method chaining when creating your charts:

var obj = new RGraph.Drawing.Background({
    id: 'cvs',
}).on('draw', function (obj)
{
    // Put your draw event code here

}).on('click', function (e, shape)
{
    // Handle the click event

}).draw();
obj.exec(function)

The exec function is documented here.

Custom RGraph events that are available

Custom RGraph events are events that RGraph fires when certain actions occur. There is a more comprehensive list of these events here . Here's some example code that show you how to add these events to your chart.

There's more documentation about events available here: Summary of events documentation

<script>
    background = new RGraph.Drawing.Background({
        id: 'cvs',
        options: {
        }
    }).draw().on('click', function (e, shape)
    {
        // Add your click event listener code here

    }).on('mousemove', function (e, shape)
    {
        // Add your mousemove event listener code here

    }).on('mouseover', function (e, shape)
    {
        // Add your mouseover event listener code here

    }).on('mouseout', function (obj)
    {
        // Add your mouseout event listener code here
    });
</script>