Radar chart API reference

Documentation about the Radar chart including information about all of the options that are available to you. The Radar chart can show multiple datasets and be filled or non-filled. It can show differences in the magnitude of the values in a given dataset.

Example

<script>
    data = [
        [16,18,14,15,14,13,16,18],
        [16,15,14,16,18,16,15,14]
    ];

    new RGraph.Radar({
        id: 'cvs',
        data: data,
        options: {
            backgroundCircles: true,
            textSize: 16,
            labels: ['Fliss','Ed','Raymond','Lilly','James','Jimbo','Lucy','Fred'],
            key: ['Market share', 'A made up figure'],
            colorsStroke: ['red', 'black'],
            colors: ['rgba(0,0,0,0)'],
            linewidth: 5,
            marginTop: 15,
            marginBottom: 15,
            marginLeft: 85,
            marginRight: 125
        }
    }).draw();
</script>

Properties

You can use these properties to control how the chart appears. You can set them by including them in the options section of the configuration as is shown above.

Chart configuration properties

PropertyDescriptionDefault
centerxIf required, you can position the chart using this instead of the margins.null
centeryIf required, you can position the chart using this instead of the margins.null
radiusIf required, you can size the chart using this instead of the margins.null

Background properties

PropertyDescriptionDefault
backgroundCirclesWhether the background circles are shown.true
backgroundCirclesCountThis controls the number of background circles that are shown.The same as labels.count
backgroundCirclesColorThis is the color of the background circles.#ddd
backgroundCirclesPolyInstead of circles the background lines can be polygons instead. So if you have 4 points you get squares, 5 points pentagons, 6 points hexagons and so on.true
backgroundCirclesSpokesThis controls how many lines there are that go from the center outwards. This doesn't apply when the poly option is being used.24

Margin properties

PropertyDescriptionDefault
marginLeftThe left margin of the chart, (the margin is where the labels and title are)).25
marginRightThe right margin of the chart, (the margin is where the labels and title are).25
marginTopThe top margin of the chart, (the margin is where the labels and title are).25
marginBottomThe bottom margin of the chart, (the margin is where the labels and title are).25

Color properties

PropertyDescriptionDefault
colorsThe colors of the radar chart(s).red
colorsAlphaIf set (a number between 0 and 1), this will be used as the alpha value of the colors of the chart.null
colorsStrokeThis is the color of the Radar chart. It can be a string or it can be an array of colors (one for each dataset).#aaa

Title properties

PropertyDescriptionDefault
titleThe title, if any, of the chart.Not set
titleFontThe font that the title is rendered in. If not specified the textFont setting is used (usually Arial).null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the textSize setting.null
titleBoldWhether the title is bold or not.true
titleItalicWhether the title is italic or not.false
titleColorThe color of the title.black
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

Labels and text properties

PropertyDescriptionDefault
labelsThe labels to use for the chart.An empty array
labelsFontThe font used to render 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
labelsOffsetThe offset for the labels.10
labelsAxesThis controls the axes that show the scale labels. Each letter stands for the appropriate axis (North, South, East and West). (An empty string)
labelsAxesFontThe font used by the labels.null
labelsAxesSizeThe size of the labels.null
labelsAxesColorThe color of the labels.null
labelsAxesBoldThis controls whether the axis labels are bold or not.null
labelsAxesItalicThis controls whether the axis labels are italic or not.null
labelsAxesCountThis controls how many scale labels that are displayed.white
textFontThe font used to render the text.Arial, Verdana, sans-serif
textColorThe color of the labels.black
textSizeThe size of the text.12
textBoldWhether the text is bold or not.false
textItalicWhether the text is italic or not.false
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

Scale properties

PropertyDescriptionDefault
scaleMaxThe optional maximum scale value. If not specified then it will be calculated.null (It's calculated)
scaleRoundWhether to round the maximum scale value up or not. This will produce slightly better scales in some instances.null
scalePointThe character used as the decimal point..
scaleThousandThe character used as the thousand separator.,
scaleDecimalsThis stipulates how many decimal places there are.0
scaleUnitsPreThese units are prepended to the scale numbers.[an empty string]
scaleUnitsPostThese units are appended to the scale numbers.[an empty string]

Axis properties

PropertyDescriptionDefault
axesColorThis is the color of the axes.black
axesLinewidthThis is the linewidth of the axes.1

Key properties

The key properties are documented on the key documentation page.

Interactive features properties

PropertyDescriptionDefault
contextmenuAn array of context menu items. More information about context menus is here.An empty array
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
tooltipsA numerically indexed array of tooltips that are shown when a bar is clicked. These can contain HTML.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
resizableDefaulting to false, this determines whether your chart will be resizable. Because of the numerous event handlers this has to install code on, This feature is unlikely to work with other dynamic features (the context menu is fine however).false
resizableHandleBackgroundWith this you can specify the background color for the resize handle. If you're adjusting the position of the handle then you may need this to make the handle stand out more.null
resizableMinwidthThis allows you to set a minimum width that the chart can be resized to.null
resizableMinheightThis allows you to set a minimum height that the chart can be resized to.null
resizableMaxwidthThis allows you to set a maximum width that the chart can be resized to.null
resizableMaxheightThis allows you to set a maximum height that the chart can be resized to.null

Event properties

PropertyDescriptionDefault
eventsClickIf you want to add your own click function you can do so by assigning it to this property. See here for details.null
eventsMousemoveIf you want to add your own mousemove function you can do so by assigning it to this property. See here for details.null
eventsMouseoverIf you want to add your own mouseover function you can do so by assigning it to this property. See here for details.null
eventsMouseoutIf you want to add your own mouseout function you can do so by assigning it to this property. See here for details.null

Miscellaneous properties

PropertyDescriptionDefault
highlightStyleBy default this is null but you can set it to a function which is called to do the chart highlighting. Its passed the shape object as an argument.null
highlightStrokeIf you use tooltips, this controls the color of the highlight stroke.gray
highlightFillIf you use tooltips, this controls the color of the highlight fill.white
highlightPointRadiusThis controls the size of the highlight when tooltips are used.2
highlightsDifferent to tooltip highlighting this adds circular points to the Radar chart.false
highlightsRadiusThe radius of the highlights. In other words this controls the size of the highlights.3
linewidthThe width of the outline.1
circleWhat value to draw a circle at. Defaults to zero (off). You could use this to represent a threshold of some sort.0
circleFillWhat color to fill the circle with.red
circleStrokeWhat color to stroke (ie The outline) the circle with.black
accumulativeIf set to true this will produce a stacked Radar chart. Obviously you must have two or more data sets, and also the data sets must have the same number of data points.false
cleartoThis is used in animations and effects as the default color to use when the canvas.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 function returns the details of any focused point on the chart. It returns:

The shape also includes textual indexes like this: shape['object'] And they are:

obj.getRadius(value)

This function returns the distance from the center for a particular value - the radius of an imaginary circle in effect.

obj.getAngle(numitems, index)

The Radar chart values are spaced equally around the chart (in terms of their angles). So the angle for a particular data point can easily be calculated. This method makes it even easier. Simply pass it the total number of data points that you have and the zero-indexed number of the one you want and this will return you an appropriate angle. eg for the fourth item out of 8 total data points you would do this: obj.getAngle(8, 3);

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 event code here
});

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

new RGraph.Radar({
    id: 'cvs',
    data: [8,6,4,3,8,7,4,9]
}).on('draw', function (e, shape)
{
    // Put ondraw code here
}).on('click', function (e, shape)
{
    // Handle click event
}).draw()
The exec option and method

The exec function is documented here.

obj.HighlightDataset(dataset_index)

If you're using the fillClick or the fillMousemove options then you may want to make use of this function - which will highlight a dataset for you. You pass it the index of the dataset (0 for the first dataset, 1 for the second etc) and this will add highlighting for you. It uses the highlightFill and highlightStroke options for the colors.

The coords and coords2 arrays

The X/Y coordinates for the points on the Radar chart are held in two different ways. The obj.coords array is one long array containing all of the coordinates for all of the datasets. The obj.coords2 on the other hand holds the same coordinates but in a multi-dimensional way - so, keeping in mind that the numbering starts at zero, obj.coords2[1][3] refers to the fourth point in the second dataset.

Highlighting data series

[No canvas support]

New in November 2012 is the ability to highlight a data series. This allows you to associate a function to run when a data series is clicked or hovered over. In addition to being able to run a function you can also specify a set of tooltips which are shown when the datasets are clicked on or hovered over. These tooltips can be shown using the mousemove or the click events. If you need it - there is a obj.HighlightDataset(dataset) method which you can use to highlight a specific dataset. The appropriate properties and their default values are:


<script>
    window.onload = (function ()
    {
        new RGraph.Radar({
            id: 'cvs',
            data: [
                [4,8,6,5,3,5,4,6,8,7],
                [4,2,3,5,1,6,5,4,5,3]
            ],
            options: {
                marginBottom: 35,
                labels: ['Bob','Richard','Luis','Pete','Gemma','Karen','Lee','Olga','Kevin','Luis'],
                colors: ['red', 'green'],
                colorsAlpha: 0.4,
                axesColor: 'rgba(0,0,0,0)',
                accumulative: true,
                backgroundCirclesPoly: true,
                colorsStroke: 'rgba(0,0,0,0)',
                textSize: 10,
                fillTooltips: ['The first datasets tooltip', 'The second datasets tooltip'])
            }
        }).draw();
    });
</script>

Giving multiple data series as a multi-dimensional array (Note: older style configuration)

As of the April 2013 stable release you can now give multiple data series as one multi-dimensional array to the constructor instead of as separate arguments. This may make life easier when you're creating a Radar chart using AJAX.

// Giving your data series as separate arguments
var radar = new RGraph.Radar('cvs', [4,8,6,3,5], [4,3,5,6,4])

// Giving your data series' as one argument
var radar = new RGraph.Radar('cvs', [[4,8,6,3,5], [4,3,5,6,4]])

Newer JSON style configuration: If you're using the newer JSON style configuration this doesn't apply. With that the configuration for datasets is:

new RGraph.Radar({
    id: 'cvs',
    data: [
        [4,8,6,3,5],
        [4,3,5,6,4]
    ],
    options: {
    }
}).draw();

Animation effects

These effects are available and can be used instead of the draw() function. There are also generic effects available which you can see here: Generic effects and transitions
<script>
    // Optional callback function that's called when the effect is complete
    function myCallback (obj)
    {
        // ...
    }

    new RGraph.Radar({
        id: 'cvs',
        data: [8,7,6,8,4,9,5,9,8],
        options: {
            marginLeft: 35
        }
    }).trace({frames: 60}, myCallback)
    // .grow({frames: 60}, myCallback)
</script>