Funnel chart API reference

Summary: Documentation about the Funnel chart including information about all of the options that are available to you. Funnel charts can show the decreasing (or increasing) values of a quantity through the various stages that a process may have.

Example

<script>
    new RGraph.Funnel({
        id: 'cvs',
        data: [100,45,45,26,21,5],
        options: {
            textBoxed: false,
            title: 'Leads through to sales',
            labels: ['A', 'B', 'C', 'D', 'E', 'F'],
            shadow: true
        }
    }).draw();
</script>

Properties

You can use these properties to control how the Funnel chart appears. You can set them by using the set() method. Eg:

myFunnel.set('name', 'value');

Margin properties

PropertyDescriptionDefault
marginLeftThe left margin of the chart.25
marginRightThe right margin of the chart.25
marginTopThe top margin of the chart.25
marginBottomThe bottom margin of the chart.25
marginLeft
The left margin of the chart.
Default: 25

marginRight
The right margin of the chart.
Default: 25

marginTop
The top margin of the chart.
Default: 25

marginBottom
The bottom margin of the chart.
Default: 25

Color properties

PropertyDescriptionDefault
colorsThese are the colors used for each segment.['red', 'green', 'gray', 'blue', 'black', 'white']
colorsStrokeThe color used for the stroke that goes around each segment.rgba(0,0,0,0)
colors
These are the colors used for each segment.
Default: ['red', 'green', 'gray', 'blue', 'black', 'white']

colorsStroke
The color used for the stroke that goes around each segment.
Default: rgba(0,0,0,0)

Labels and text properties

PropertyDescriptionDefault
labelsAn array of the labels to be used on the chart.An empty array
labelsXUse this to specify an X position for labels.null
labelsSticksIf your labels are offset you can use this to show indicating sticks. See the examples in the download for how you can use them.null
labelsFontThe font used by the labels.null
labelsSizeThe size of the labels.null
labelsColorThe color of the labels.null
labelsBoldWhether the labels are bold or not.null
labelsItalicWhether the labels are italic or not.null
textFontThe font used to render the text on the chart.Arial, Verdana, sans-serif
textColorThe color of the text on the chart.black
textSizeThe size of the text on the chart.12
textBoldWhether the text on the chart is bold or not.false
textItalicWhether the text on the chart is italic or not.false
textHalignThe horizontal alignment of the text. Can be center or left.left
textAccessibleA new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>
true
textAccessibleOverflowThis can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small margins if you wish.visible
textAccessiblePointereventsThis controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).true
labels
An array of the labels to be used on the chart.
Default: An empty array

labelsX
Use this to specify an X position for labels.
Default: null

labelsSticks
If your labels are offset you can use this to show indicating sticks. See the examples in the download for how you can use them.
Default: null

labelsFont
The font used by the labels.
Default: null

labelsSize
The size of the labels.
Default: null

labelsColor
The color of the labels.
Default: null

labelsBold
Whether the labels are bold or not.
Default: null

labelsItalic
Whether the labels are italic or not.
Default: null

textFont
The font used to render the text on the chart.
Default: Arial, Verdana, sans-serif

textColor
The color of the text on the chart.
Default: black

textSize
The size of the text on the chart.
Default: 12

textBold
Whether the text on the chart is bold or not.
Default: false

textItalic
Whether the text on the chart is italic or not.
Default: false

textHalign
The horizontal alignment of the text. Can be center or left.
Default: left

textAccessible
A new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>

Default: true

textAccessibleOverflow
This can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small margins if you wish.
Default: visible

textAccessiblePointerevents
This controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).
Default: true

Title properties

PropertyDescriptionDefault
titleThe title of the chart, if any.null
titleFontThe font that the title is rendered in.null
titleSizeThe size of the title.null
titleBoldWhether the title is bold or not.null
titleItalicWhether the title is italic or not.null
titleColorThe color of the title.null
titleBackgroundThe background color (if any) for the title.null
titleXTo give the exact X coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null
titleYTo give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null
title
The title of the chart, if any.
Default: null

titleFont
The font that the title is rendered in.
Default: null

titleSize
The size of the title.
Default: null

titleBold
Whether the title is bold or not.
Default: null

titleItalic
Whether the title is italic or not.
Default: null

titleColor
The color of the title.
Default: null

titleBackground
The background color (if any) for the title.
Default: null

titleX
To give the exact X coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null

titleY
To give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null

Shadow properties

PropertyDescriptionDefault
shadowWhether a drop shadow is applied to the Funnel chart.false
shadowColorThe color of the drop shadow.#666
shadowBlurThe severity of the shadow blurring effect.3
shadowOffsetxThe X offset of the shadow.3
shadowOffsetyThe Y offset of the shadow.3
shadow
Whether a drop shadow is applied to the Funnel chart.
Default: false

shadowColor
The color of the drop shadow.
Default: #666

shadowBlur
The severity of the shadow blurring effect.
Default: 3

shadowOffsetx
The X offset of the shadow.
Default: 3

shadowOffsety
The Y offset of the shadow.
Default: 3

Interactive features properties

PropertyDescriptionDefault
contextmenuAn array of context menu items. More information about context menus is here.[] (An empty array)
tooltipsAn array of tooltips for the Funnel chart segments.null
tooltipsEffectThe effect used for showing tooltips. Can be either fade or none.fade
tooltipsCssClassThis is the name of the CSS class the chart uses.RGraph_tooltip
tooltipsOverrideIf you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.null
tooltipsNohideonclearNot an option that you'll need particularly often if at all. Setting this to true means that when you call the RGraph.clear() API function tooltips DO NOT get hidden.false
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotatableColorIf you do not allow the use of the palette, then this will be the only color allowed for annotations.black
annotatableLinewidthThis is the linewidth of the annotations.1
contextmenu
An array of context menu items. More information about context menus is here.
Default: [] (An empty array)

tooltips
An array of tooltips for the Funnel chart segments.
Default: null

tooltipsEffect
The effect used for showing tooltips. Can be either fade or none.
Default: fade

tooltipsCssClass
This is the name of the CSS class the chart uses.
Default: RGraph_tooltip

tooltipsOverride
If you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.
Default: null

tooltipsNohideonclear
Not an option that you'll need particularly often if at all. Setting this to true means that when you call the RGraph.clear() API function tooltips DO NOT get hidden.
Default: false

annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false

annotatableColor
If you do not allow the use of the palette, then this will be the only color allowed for annotations.
Default: black

annotatableLinewidth
This is the linewidth of the annotations.
Default: 1

Key properties

The key properties are documented on the key documentation page.

Miscellaneous properties

PropertyDescriptionDefault
highlightStyleBy default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument.null
highlightStrokeIf you use tooltips, this controls the color of the highlight stroke.black
highlightFillIf you use tooltips, this controls the color of the highlight fill.rgba(255,255,255,0.5)
cleartoThis is used in animations and effects as the default color to use when the canvas.null
highlightStyle
By default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument.
Default: null

highlightStroke
If you use tooltips, this controls the color of the highlight stroke.
Default: black

highlightFill
If you use tooltips, this controls the color of the highlight fill.
Default: rgba(255,255,255,0.5)

clearto
This is used in animations and effects as the default color to use when the canvas.
Default: null

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 which segment has been clicked on or hovered over. It returns an object which has the following indexes available:
object The chart object
coords This is an array of 8 numbers that represent the coordinates of each of the four points that allow you to recreate the segment if required.
dataset For a funnel chart there's only ever one dataset so this is always zero.
index This is the zero-indexed index of the relevant segment.
sequentialIndex As there's only ever one dataset on a Funnel chart this is exactly the same as the index value.
tooltip If a tooltip is associated with this segment 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>
    funnel.canvas.onclick = function (e)
    {
        RGraph.redraw();
    
        var canvas  = e.target,
            obj     = canvas.__object__,
            shape   = obj.getShape(e);

        if (shape) {
            var x1 = shape.coords[0],
                y1 = shape.coords[1],
                x2 = shape.coords[2],
                y2 = shape.coords[3],
                x3 = shape.coords[4],
                y3 = shape.coords[5],
                x4 = shape.coords[6],
                y4 = shape.coords[7];
            
            RGraph.path({
                object: obj,
                  path: 'b m % % l % % l % % l % % c s black f red',
                  args: [x1, y1, x2, y2, x3, y3, x4, y4]
            });
        }
    }
</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:

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

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>
    funnel = new RGraph.Funnel({
        id: 'cvs',
        data: [100,60,54,32,25,10],
        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>