Radar charts documentation

 

Example

<script>
    // The data to be represented on the Radar chart.
    var data = [
        [16,18,14,15,14,13,16,18],
        [16,15,14,16,18,16,15,14]
    ];

    // Create the Radar chart. The arguments are the canvas ID and the data to be shown on the chart.
    var radar = new RGraph.Radar({
        id: 'cvs',
        data: data,
        options: {
            backgroundCircles: true,
            colors: ['rgba(255,0,0,0.5)'],
            textSize: 16,
            labels: ['Fliss','Ed','Raymond','Lilly','James','Jimbo','Lucy','Fred'],
            key: ['Market share', 'A made up figure'],
            strokestyle: ['red', 'black'],
            colors: ['rgba(0,0,0,0)'],
            linewidth: 5,
            gutterTop: 15,
            gutterBottom: 15,
            gutterLeft: 85,
            gutterRight: 125
        }
    }).draw();
</script>

The example file is here.

 

Properties

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

Layout style:     
  

Chart configuration

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

Background

PropertyDescriptionDefault
backgroundCirclesWhether the background circles are shown.true
backgroundCirclesCountThis controls the number of background circles that are shownThe 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.false
backgroundCirclesSpokesThis controls how many lines there are that go from the center outwards.24

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the chart, (the gutter is where the labels and title are)).25
gutterRightThe right gutter of the chart, (the gutter is where the labels and title are).25
gutterTopThe top gutter of the chart, (the gutter is where the labels and title are).25
gutterBottomThe bottom gutter of the chart, (the gutter is where the labels and title are).25

Colors

PropertyDescriptionDefault
colorsThe colors of the radar chart(s).red
colorsAlphaIf set (a number between 0 nd 1), this will be used as the alpha value of the colors of the chart.null

Titles

PropertyDescriptionDefault
titleThe title, if any, of the chart.Not set
titleFontThe font that the title is rendered in. If not specified the text.font setting is used (usually Arial)null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the text.size 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 thisnull
titleYTo give the exact Y coordinate for the title - use thisnull

Labels and text

PropertyDescriptionDefault
labelsThe labels to use for the chart.An empty array
labelsColorThe color of the labelsnull (same as textColor)
labelsAxesThis controls the axes that show the scale labels. Each letter stands for the appropriate axis (North, South, East and West) (An empty string)
labelsAxesBoxedThis controls whether the axis labels are bold or not. It should be an array of booleans (true/false).null (but it is set to an array of true values in the Draw() method)
labelsAxesBoxedZeroThis controls whether the zero axis label is bold or not.true
labelsAxesBoxedBackgroundThis controls the background color of the labels.rgba(255,255,255,0.9)
labelsAxesBoldThis controls whether the axis labels are bold or not.false
labelsAxesBoldZeroThis controls whether the zero axis label is bold or not.false
labelsOffsetThe offset for the labels.10
labelsBoxedThis determines whether the labels have a box drawn around them.true
labelsBackgroundFillThis is the background color of the labels if thy're boxed.white
labelsCountThis controls how many scale labels that are displayed.white
textFontThe font used to render the text.Arial
textColorThe color of the labels.black
textSizeThe size of the text.10
textSizeScaleIf you want to specify a different text size for the scale you can do so with this property.null
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 gutters 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

PropertyDescriptionDefault
ymaxThe optional maximum Y 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

Axis properties

PropertyDescriptionDefault
numxticksThe number of X tickmarks.10
numyticksThe number of Y tickmarks.10
axesColorThis is the color of the axes.black

Miscellaneous

PropertyDescriptionDefault
highlightStrokeIf you use tooltips, this controls the color of the highlight stroke.gray
highlightFillIf you use tooltips, this controls the colour 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
highlightsColorThe color of the highlights.true
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

Key

The key properties are documented on the key documentation page.

Interactive features

PropertyDescriptionDefault
contextmenuAn array of context menu items. More information on context menus is here.An empty array
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotateColorIf you do not allow the use of the palette, then this will be the only colour allowed for annotations.black
annotateLinewidthThis is the line width 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 pagenull
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 tooltip 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
resizeHandleBackgroundWith 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

Zoom

PropertyDescriptionDefault
zoomFactorThis is the factor that the chart will be zoomed by (bigger values means more zoom)1.5
zoomFadeInWhether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomFadeOutWhether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomHdirThe horizontal direction of the zoom. Possible values are: left, center, rightright
zoomVdirThe vertical direction of the zoom. Possible values are: up, center, downdown
zoomDelayThe delay (in milliseconds) between frames.50
zoomFramesThe number of frames in the zoom animation.10
zoomShadowWhether or not the zoomed canvas has a shadow or not.true

Events

PropertyDescriptionDefault
eventsClickIf you want to add your own onclick function you can do so by assigning it to this property. See here for details.null
eventsMousemoveIf you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.null
eventsMouseoverIf you want to add your own onmouseover function you can do so by assigning it to this property. See here for details.null
eventsMouseoutIf you want to add your own onmouseout function you can do so by assigning it to this property. See here for details.null

Miscellaneous

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. Its passed the shape object as an argument.null

 

Methods

 

obj.get(name)

An accessor that you can use to retrieve the value of properties.

 

obj.set(name, value)

An accessor that you can use to set the value of properties.

 

obj.getShape(event)

This function returns the details of any focused point on the chart. It returns:

  • The chart object
  • The X coordinate
  • The Y coordinate
  • The index of the applicable dataset (if you only yse one dataset this will always be 0)
  • The index of the point within the dataset

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

  • object
  • x
  • y
  • dataset
  • tooltip
  • index

 

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 vlues are spaced equally around the chat (in terms of their angle). So the angle for a particular data point can be easily 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, func)

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 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:

var obj = 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 fill.click or the fill.mousemove 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) a\nd this will add highlighting for you. It uses the highlight.fill and highlight.strokeoptions 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 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 mouseovered. In addition to being able to run a function you can also sspecify a set of tooltips which are shown when the datasets are clicked on or mouseover'ed. These tooltips can be shown using the mousemove or the click events. If you need it - there is an obj.HighlightDataset(dataset) method which you can use to highlight a specific dataset. The appropriate properties and their default values are:

  • fill.click (null - should be a function)
  • fill.mousemove (null - should be a function)
  • fill.tooltips (null - should be an array of strings)
  • fill.click.highlight (false)
  • fill.mousemove.highlight (false)
  • fill.highlight.fill (rgba(255,255,255,0.7))
  • fill.highlight.stroke (rgba(0,0,0,0))
  • fill.mousemove.redraw (false)

<script>
    window.onload = (function ()
    {
        var radar = 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: {
                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,
                strokestyle: 'rgba(0,0,0,0)',
                textAccessible: true,
                textSize: 14,
                fillTooltips: ['The first datasets tooltip', 'The second datasets tooltip'])
            }
        }).draw();
    });
</script>

 

Giving multiple data series as a multidimensional 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 seperate arguments. This may make life easier when you're creating a Radar chart using AJAX.

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

// Giving 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:

var radar = 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)
    {
        // ...
    }

    var obj = new RGraph.Radar({
        id: 'cvs',
        data: [8,7,6,8,4,9,5,9,8],
        options: {
            gutterLeft: 35
        }
    }).trace({frames: 60}, myCallback)
    // .grow({frames: 60}, myCallback)
</script>
© Copyright Richard Heyes 2008-2017