Radar charts documentation

Share RGraph:   

 

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.

 

Chart configuration

centerx
If required, you can position the Meter chart using this instead of the gutters.
Default: null

centery
If required, you can position the Meter chart using this instead of the gutters.
Default: null

radius
If required, you can size the Meter chart using this instead of the gutters.
Default: null

 

Background

backgroundCircles
Whether the background circles are shown.
Default: true

backgroundCirclesCount
This controls the number of background circles that are shown
Default: The same as labels.count

backgroundCirclesColor
This is the color of the background circles.
Default: #ddd

backgroundCirclesPoly
Instead 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.
Default: false

backgroundCirclesSpokes
This controls how many lines there are that go from the center outwards.
Default: 24

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 25

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 25

 

Colors

colors
The colors of the radar chart(s).
Default: red

colorsAlpha
If set (a number between 0 nd 1), this will be used as the alpha value of the colors of the chart.
Default: null

 

Titles

title
The title, if any, of the chart.
Default: Not set

titleFont
The font that the title is rendered in. If not specified the text.font setting is used (usually Arial)
Default: null

titleSize
The size of the title. If not specified the size is usually 2pt bigger than the text.size setting.
Default: null

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

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

titleColor
The color of the title.
Default: black

titleX
To give the exact X coordinate for the title - use this
Default: null

titleY
To give the exact Y coordinate for the title - use this
Default: null

 

Labels and text

labels
The labels to use for the chart.
Default: An empty array

labelsColor
The color of the labels
Default: null (same as textColor)

labelsAxes
This controls the axes that show the scale labels. Each letter stands for the appropriate axis (North, South, East and West)
Default: (An empty string)

labelsAxesBoxed
This controls whether the axis labels are bold or not. It should be an array of booleans (true/false).
Default: null (but it is set to an array of true values in the Draw() method)

labelsAxesBoxedZero
This controls whether the zero axis label is bold or not.
Default: true

labelsAxesBold
This controls whether the axis labels are bold or not.
Default: false

labelsAxesBoldZero
This controls whether the zero axis label is bold or not.
Default: false

labelsOffset
The offset for the labels.
Default: 10

labelsBoxed
This determines whether the labels have a box drawn around them.
Default: true

labelsBackgroundFill
This is the background color of the labels if thy're boxed.
Default: white

labelsCount
This controls how many scale labels that are displayed.
Default: white

textFont
The font used to render the text.
Default: Arial

textColor
The color of the labels.
Default: black

textSize
The size of the text.
Default: 10

textSizeScale
If you want to specify a different text size for the scale you can do so with this property.
Default: null

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

 

Scale

ymax
The optional maximum Y scale value. If not specified then it will be calculated.
Default: null (It's calculated)

scaleRound
Whether to round the maximum scale value up or not. This will produce slightly better scales in some instances.
Default: null

scalePoint
The character used as the decimal point.
Default: .

scaleThousand
The character used as the thousand separator
Default: ,

scaleDecimals
This stipulates how many decimal places there are.
Default: 0

 

Axis properties

numxticks
The number of X tickmarks.
Default: 10

numyticks
The number of Y tickmarks.
Default: 10

axesColor
This is the color of the axes.
Default: black

 

Miscellaneous

The key properties are documented on the key documentation page.

 

Key


Warning: Invalid argument supplied for foreach() in /homepages/46/d548322256/htdocs/www/includes/functions.php on line 774

 

Interactive features

contextmenu
An array of context menu items. More information on context menus is here.
Default: An empty array

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

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

annotateLinewidth
This is the line width of the annotations.
Default: 1

tooltips
A numerically indexed array of tooltips that are shown when a bar is clicked. These can contain HTML.
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

tooltipsCoordsPage
If set to true the tooltips will be positioned using the .pageX and .pageY coordinates. If you use canvas tags that are offset from the .pageX and .pageY coordinates - this can help with tooltip positioning.
Default: false

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 tooltip DO NOT get hidden.
Default: false

resizable
Defaulting 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).
Default: false

resizeHandleBackground
With 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.
Default: null

resizableMaxwidth
This allows you to set a maximum width that the chart can be resized to.
Default: null

resizableMaxheight
This allows you to set a maximum height that the chart can be resized to.
Default: null

 

Zoom

zoomFactor
This is the factor that the chart will be zoomed by (bigger values means more zoom)
Default: 1.5

zoomFadeIn
Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomFadeOut
Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomHdir
The horizontal direction of the zoom. Possible values are: left, center, right
Default: right

zoomVdir
The vertical direction of the zoom. Possible values are: up, center, down
Default: down

zoomDelay
The delay (in milliseconds) between frames.
Default: 50

zoomFrames
The number of frames in the zoom animation.
Default: 10

zoomShadow
Whether or not the zoomed canvas has a shadow or not.
Default: true

 

Events

eventsClick
If you want to add your own onclick function you can do so by assigning it to this property. See here for details.
Default: null

eventsMousemove
If you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.
Default: null

eventsMouseover
If you want to add your own onmouseover function you can do so by assigning it to this property. See here for details.
Default: null

 

Miscellaneous

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


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

Comments

Add a new comment...