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.

Radar Chart - 图1

config setup

  1. const config = {
  2. type: 'radar',
  3. data: data,
  4. options: {
  5. elements: {
  6. line: {
  7. borderWidth: 3
  8. }
  9. }
  10. },
  11. };
  1. const data = {
  2. labels: [
  3. 'Eating',
  4. 'Drinking',
  5. 'Sleeping',
  6. 'Designing',
  7. 'Coding',
  8. 'Cycling',
  9. 'Running'
  10. ],
  11. datasets: [{
  12. label: 'My First Dataset',
  13. data: [65, 59, 90, 81, 56, 55, 40],
  14. fill: true,
  15. backgroundColor: 'rgba(255, 99, 132, 0.2)',
  16. borderColor: 'rgb(255, 99, 132)',
  17. pointBackgroundColor: 'rgb(255, 99, 132)',
  18. pointBorderColor: '#fff',
  19. pointHoverBackgroundColor: '#fff',
  20. pointHoverBorderColor: 'rgb(255, 99, 132)'
  21. }, {
  22. label: 'My Second Dataset',
  23. data: [28, 48, 40, 19, 96, 27, 100],
  24. fill: true,
  25. backgroundColor: 'rgba(54, 162, 235, 0.2)',
  26. borderColor: 'rgb(54, 162, 235)',
  27. pointBackgroundColor: 'rgb(54, 162, 235)',
  28. pointBorderColor: '#fff',
  29. pointHoverBackgroundColor: '#fff',
  30. pointHoverBorderColor: 'rgb(54, 162, 235)'
  31. }]
  32. };

Example Usage

  1. var myRadarChart = new Chart(ctx, {
  2. type: 'radar',
  3. data: data,
  4. options: options
  5. });

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.

NameTypeScriptableIndexableDefault
backgroundColorColorYes-‘rgba(0, 0, 0, 0.1)’
borderCapStylestringYes-‘butt’
borderColorColorYes-‘rgba(0, 0, 0, 0.1)’
borderDashnumber[]Yes-[]
borderDashOffsetnumberYes-0.0
borderJoinStylestringYes-‘miter’
borderWidthnumberYes-3
hoverBackgroundColorColorYes-undefined
hoverBorderCapStylestringYes-undefined
hoverBorderColorColorYes-undefined
hoverBorderDashnumber[]Yes-undefined
hoverBorderDashOffsetnumberYes-undefined
hoverBorderJoinStylestringYes-undefined
hoverBorderWidthnumberYes-undefined
clipnumber|object--undefined
datanumber[]--required
fillboolean|stringYes-false
labelstring--‘’
ordernumber--0
tensionnumber--0
pointBackgroundColorColorYesYes‘rgba(0, 0, 0, 0.1)’
pointBorderColorColorYesYes‘rgba(0, 0, 0, 0.1)’
pointBorderWidthnumberYesYes1
pointHitRadiusnumberYesYes1
pointHoverBackgroundColorColorYesYesundefined
pointHoverBorderColorColorYesYesundefined
pointHoverBorderWidthnumberYesYes1
pointHoverRadiusnumberYesYes4
pointRadiusnumberYesYes3
pointRotationnumberYesYes0
pointStylestring|ImageYesYes‘circle’
spanGapsboolean--undefined

General

NameDescription
clipHow 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}
labelThe label for the dataset which appears in the legend and tooltips.
orderThe drawing order of dataset.

Point Styling

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

NameDescription
pointBackgroundColorThe fill color for points.
pointBorderColorThe border color for points.
pointBorderWidthThe width of the point border in pixels.
pointHitRadiusThe pixel size of the non-displayed point that reacts to mouse events.
pointRadiusThe radius of the point shape. If set to 0, the point is not rendered.
pointRotationThe rotation of the point in degrees.
pointStyleStyle 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:

NameDescription
backgroundColorThe line fill color.
borderCapStyleCap style of the line. See MDNRadar Chart - 图2 (opens new window).
borderColorThe line color.
borderDashLength and spacing of dashes. See MDNRadar Chart - 图3 (opens new window).
borderDashOffsetOffset for line dashes. See MDNRadar Chart - 图4 (opens new window).
borderJoinStyleLine joint style. See MDNRadar Chart - 图5 (opens new window).
borderWidthThe line width (in pixels).
fillHow to fill the area under the line. See area charts.
tensionBezier curve tension of the line. Set to 0 to draw straight lines.
spanGapsIf 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:

NameDescription
pointHoverBackgroundColorPoint background color when hovered.
pointHoverBorderColorPoint border color when hovered.
pointHoverBorderWidthBorder width of point when hovered.
pointHoverRadiusThe 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.

NameTypeDefaultDescription
spanGapsbooleanfalseIf 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.

  1. options = {
  2. scales: {
  3. r: {
  4. angleLines: {
  5. display: false
  6. },
  7. suggestedMin: 50,
  8. suggestedMax: 100
  9. }
  10. }
  11. };

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.

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

  1. data: {
  2. labels: ['Running', 'Swimming', 'Eating', 'Cycling'],
  3. datasets: [{
  4. data: [20, 10, 4, 2]
  5. }]
  6. }

Internal data format

{x, y}