Chart.js/docs/charts/radar.md
Evert Timberg ed2b96eeaf
Switch docs to Vuepress to match other chart.js repositories (#8751)
* Initial work

* Update doc commands

* Updated sidebar config

* Move docs

* Update theme version and enable

* Convert to chart.js sample

* Update scripts to point to local build

* Chart.js from local build

* Simplify getting-started example

* Axis docs updated except for imported content

* Common ticks import works

* Chart type docs ported to editor plugin

* Last pages to use editor

* Fix small errors

* Frontmatter title to heading

* Remove duplicate example

* Update sidebar

* Add paths

* Remove paths

* Add getting-started back

* Update menus and add copyright to license section of the docs

* Add GA plugin

* Style sub-groups

* Remove unneeded license page since it is covered on the main page

* Remove docusaurus readme page

* Remove docusaurus files

* Fix issues in docs

* Build and deploy scripts for docs work

* Conditional base URL for nice local testing

* Use eslint-plugin-markdown

* Remove hard coded lines

* Remove mentions of docusaurus

Co-authored-by: Jukka Kurkela <jukka.kurkela@gmail.com>
2021-03-30 10:32:39 -04:00

8.7 KiB

Radar Chart

A radar chart is a way of showing multiple data points and the variation between them.

They are often useful for comparing the points of two or more different data sets.

// <block:setup:1>
const data = {
  labels: [
    'Eating',
    'Drinking',
    'Sleeping',
    'Designing',
    'Coding',
    'Cycling',
    'Running'
  ],
  datasets: [{
    label: 'My First Dataset',
    data: [65, 59, 90, 81, 56, 55, 40],
    fill: true,
    backgroundColor: 'rgba(255, 99, 132, 0.2)',
    borderColor: 'rgb(255, 99, 132)',
    pointBackgroundColor: 'rgb(255, 99, 132)',
    pointBorderColor: '#fff',
    pointHoverBackgroundColor: '#fff',
    pointHoverBorderColor: 'rgb(255, 99, 132)'
  }, {
    label: 'My Second Dataset',
    data: [28, 48, 40, 19, 96, 27, 100],
    fill: true,
    backgroundColor: 'rgba(54, 162, 235, 0.2)',
    borderColor: 'rgb(54, 162, 235)',
    pointBackgroundColor: 'rgb(54, 162, 235)',
    pointBorderColor: '#fff',
    pointHoverBackgroundColor: '#fff',
    pointHoverBorderColor: 'rgb(54, 162, 235)'
  }]
};
// </block:setup>

// <block:config:0>
const config = {
  type: 'radar',
  data: data,
  options: {
    elements: {
      line: {
        borderWidth: 3
      }
    }
  },
};
// </block:config>

module.exports = {
  actions: [],
  config: config,
};

Example Usage

var myRadarChart = new Chart(ctx, {
    type: 'radar',
    data: data,
    options: options
});

Dataset Properties

The radar chart allows a number of properties to be specified for each dataset. These are used to set display properties for a specific dataset. For example, the colour of a line is generally set this way.

Name Type Scriptable Indexable Default
backgroundColor Color Yes - 'rgba(0, 0, 0, 0.1)'
borderCapStyle string Yes - 'butt'
borderColor Color Yes - 'rgba(0, 0, 0, 0.1)'
borderDash number[] Yes - []
borderDashOffset number Yes - 0.0
borderJoinStyle string Yes - 'miter'
borderWidth number Yes - 3
hoverBackgroundColor Color Yes - undefined
hoverBorderCapStyle string Yes - undefined
hoverBorderColor Color Yes - undefined
hoverBorderDash number[] Yes - undefined
hoverBorderDashOffset number Yes - undefined
hoverBorderJoinStyle string Yes - undefined
hoverBorderWidth number Yes - undefined
clip number|object - - undefined
data number[] - - required
fill boolean|string Yes - false
label string - - ''
order number - - 0
tension number - - 0
pointBackgroundColor Color Yes Yes 'rgba(0, 0, 0, 0.1)'
pointBorderColor Color Yes Yes 'rgba(0, 0, 0, 0.1)'
pointBorderWidth number Yes Yes 1
pointHitRadius number Yes Yes 1
pointHoverBackgroundColor Color Yes Yes undefined
pointHoverBorderColor Color Yes Yes undefined
pointHoverBorderWidth number Yes Yes 1
pointHoverRadius number Yes Yes 4
pointRadius number Yes Yes 3
pointRotation number Yes Yes 0
pointStyle string|Image Yes Yes 'circle'
spanGaps boolean - - undefined

General

Name Description
clip How to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea. Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}
label The label for the dataset which appears in the legend and tooltips.
order The drawing order of dataset.

Point Styling

The style of each point can be controlled with the following properties:

Name Description
pointBackgroundColor The fill color for points.
pointBorderColor The border color for points.
pointBorderWidth The width of the point border in pixels.
pointHitRadius The pixel size of the non-displayed point that reacts to mouse events.
pointRadius The radius of the point shape. If set to 0, the point is not rendered.
pointRotation The rotation of the point in degrees.
pointStyle Style of the point. more...

All these values, if undefined, fallback first to the dataset options then to the associated elements.point.* options.

Line Styling

The style of the line can be controlled with the following properties:

Name Description
backgroundColor The line fill color.
borderCapStyle Cap style of the line. See MDN.
borderColor The line color.
borderDash Length and spacing of dashes. See MDN.
borderDashOffset Offset for line dashes. See MDN.
borderJoinStyle Line joint style. See MDN.
borderWidth The line width (in pixels).
fill How to fill the area under the line. See area charts.
tension Bezier curve tension of the line. Set to 0 to draw straight lines.
spanGaps If true, lines will be drawn between points with no or null data. If false, points with null data will create a break in the line.

If the value is undefined, spanGaps fallback to the associated chart configuration options. The rest of the values fallback to the associated elements.line.* options.

Interactions

The interaction with each point can be controlled with the following properties:

Name Description
pointHoverBackgroundColor Point background color when hovered.
pointHoverBorderColor Point border color when hovered.
pointHoverBorderWidth Border width of point when hovered.
pointHoverRadius The radius of the point when hovered.

Configuration Options

The radar chart defines the following configuration options. These options are looked up on access, and form together with the global chart configuration, Chart.defaults, the options of the chart.

Name Type Default Description
spanGaps boolean false If false, null data causes a break in the line.

Scale Options

The radar chart supports only a single scale. The options for this scale are defined in the scale property. The options for this scale are defined in the scale property, which can be referenced from the Linear Radial Axis page.

options = {
    scales: {
        r: {
            angleLines: {
                display: false
            },
            suggestedMin: 50,
            suggestedMax: 100
        }
    }
};

Default Options

It is common to want to apply a configuration setting to all created radar charts. The global radar chart settings are stored in Chart.overrides.radar. Changing the global options only affects charts created after the change. Existing charts are not changed.

Data Structure

The data property of a dataset for a radar chart is specified as an array of numbers. Each point in the data array corresponds to the label at the same index.

data: [20, 10]

For a radar chart, to provide context of what each point means, we include an array of strings that show around each point in the chart.

data: {
    labels: ['Running', 'Swimming', 'Eating', 'Cycling'],
    datasets: [{
        data: [20, 10, 4, 2]
    }]
}

Internal data format

{x, y}