Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

05-Radar-Chart.md 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. title: Radar Chart
  3. anchor: radar-chart
  4. ---
  5. ### Introduction
  6. A radar chart is a way of showing multiple data points and the variation between them.
  7. They are often useful for comparing the points of two or more different data sets.
  8. <div class="canvas-holder">
  9. <canvas width="250" height="125"></canvas>
  10. </div>
  11. ### Example Usage
  12. ```javascript
  13. var myRadarChart = new Chart(ctx, {
  14. type: 'radar',
  15. data: data,
  16. options: options
  17. });
  18. ```
  19. ### Data Structure
  20. The following options can be included in a radar chart dataset to configure options for that specific dataset.
  21. All point* properties can be specified as an array. If these are set to an array value, the first value applies to the first point, the second value to the second point, and so on.
  22. Property | Type | Usage
  23. --- | --- | ---
  24. data | `Array<Number>` | The data to plot in a line
  25. label | `String` | The label for the dataset which appears in the legend and tooltips
  26. fill | `Boolean` | If true, fill the area under the line
  27. lineTension | `Number` | Bezier curve tension of the line. Set to 0 to draw straightlines. *Note* This was renamed from 'tension' but the old name still works.
  28. backgroundColor | `Color` | The fill color under the line. See [Colors](#getting-started-colors)
  29. borderWidth | `Number` | The width of the line in pixels
  30. borderColor | `Color` | The color of the line.
  31. borderCapStyle | `String` | Cap style of the line. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap)
  32. borderDash | `Array<Number>` | Length and spacing of dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)
  33. borderDashOffset | `Number` | Offset for line dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
  34. borderJoinStyle | `String` | Line joint style. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin)
  35. pointBorderColor | `Color or Array<Color>` | The border color for points.
  36. pointBackgroundColor | `Color or Array<Color>` | The fill color for points
  37. pointBorderWidth | `Number or Array<Number>` | The width of the point border in pixels
  38. pointRadius | `Number or Array<Number>` | The radius of the point shape. If set to 0, nothing is rendered.
  39. pointHoverRadius | `Number or Array<Number>` | The radius of the point when hovered
  40. hitRadius | `Number or Array<Number>` | The pixel size of the non-displayed point that reacts to mouse events
  41. pointHoverBackgroundColor | `Color or Array<Color>` | Point background color when hovered
  42. pointHoverBorderColor | `Color or Array<Color>` | Point border color when hovered
  43. pointHoverBorderWidth | `Number or Array<Number>` | Border width of point when hovered
  44. pointStyle | `String or Array<String>` | The style of point. Options include 'circle', 'triangle', 'rect', 'rectRot', 'cross', 'crossRot', 'star', 'line', and 'dash'
  45. An example data object using these attributes is shown below.
  46. ```javascript
  47. var data = {
  48. labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
  49. datasets: [
  50. {
  51. label: "My First dataset",
  52. backgroundColor: "rgba(179,181,198,0.2)",
  53. borderColor: "rgba(179,181,198,1)",
  54. pointBackgroundColor: "rgba(179,181,198,1)",
  55. pointBorderColor: "#fff",
  56. pointHoverBackgroundColor: "#fff",
  57. pointHoverBorderColor: "rgba(179,181,198,1)",
  58. data: [65, 59, 90, 81, 56, 55, 40]
  59. },
  60. {
  61. label: "My Second dataset",
  62. backgroundColor: "rgba(255,99,132,0.2)",
  63. borderColor: "rgba(255,99,132,1)",
  64. pointBackgroundColor: "rgba(255,99,132,1)",
  65. pointBorderColor: "#fff",
  66. pointHoverBackgroundColor: "#fff",
  67. pointHoverBorderColor: "rgba(255,99,132,1)",
  68. data: [28, 48, 40, 19, 96, 27, 100]
  69. }
  70. ]
  71. };
  72. ```
  73. 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.
  74. For the radar chart data, we have an array of datasets. Each of these is an object, with a fill colour, a stroke colour, a colour for the fill of each point, and a colour for the stroke of each point. We also have an array of data values.
  75. The label key on each dataset is optional, and can be used when generating a scale for the chart.
  76. ### Chart Options
  77. These are the customisation options specific to Radar charts. These options are merged with the [global chart configuration options](#global-chart-configuration), and form the options of the chart.
  78. The default options for radar chart are defined in `Chart.defaults.radar`.
  79. Name | Type | Default | Description
  80. --- | --- | --- | ---
  81. scale | Object | [See Scales](#scales) and [Defaults for Radial Linear Scale](#scales-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid lines.
  82. *scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
  83. *elements*.line | Object | | Options for all line elements used on the chart, as defined in the global elements, duplicated here to show Radar chart specific defaults.
  84. *elements.line*.lineTension | Number | 0 | Tension exhibited by lines when calculating splineCurve. Setting to 0 creates straight lines.
  85. You can override these for your `Chart` instance by passing a second argument into the `Radar` method as an object with the keys you want to override.
  86. For example, we could have a radar chart without a point for each on piece of data by doing the following:
  87. ```javascript
  88. new Chart(ctx, {
  89. type: "radar",
  90. data: data,
  91. options: {
  92. scale: {
  93. reverse: true,
  94. ticks: {
  95. beginAtZero: true
  96. }
  97. }
  98. }
  99. });
  100. // This will create a chart with all of the default options, merged from the global config,
  101. // and the Radar chart defaults but this particular instance's scale will be reversed as
  102. // well as the ticks beginning at zero.
  103. ```
  104. We can also change these defaults values for each Radar type that is created, this object is available at `Chart.defaults.radar`.