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

    new RGraph.Drawing.Background({
        id: 'cvs',
        options: {
            title: 'The background object',
            tooltips: ['The drawing API <b>background</b> object'],
            tooltipsCss: {
                fontSize: '16pt'
            textSize: 18,
            textBold: true



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.

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 strings are expanded for you (where the tooltip text is retrieved from the HTML tag with the matching ID).
    background.canvas.onclick = function (e)
        var canvas =,
            obj    = canvas.__object__,
            shape  = obj.getShape(e),
            prop   =,
            width  = canvas.width - prop.marginLeft - prop.marginRight,
            height = canvas.height - prop.marginTop - prop.marginBottom;

        if (shape) {            
            // Highlight the main body of the Background object.
                'lw 10 b r % % % % s black f rgba(255,0,0,0.25)',
                prop.marginLeft, prop.marginTop, width, height

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


The exec function is documented here.