Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

08-Bubble-Chart.md 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ---
  2. title: Bubble Chart
  3. anchor: bubble-chart
  4. ---
  5. ### Introduction
  6. A bubble chart is used to display three dimensions of data at the same time. The location of the bubble is determined by the first two dimensions and the corresponding horizontal and vertical axes. The third dimension is represented by the size of the individual bubbles.
  7. <div class="canvas-holder">
  8. <canvas width="250" height="125"></canvas>
  9. </div>
  10. <br>
  11. ### Example Usage
  12. ```javascript
  13. // For a bubble chart
  14. var myBubbleChart = new Chart(ctx,{
  15. type: 'bubble',
  16. data: data,
  17. options: options
  18. });
  19. ```
  20. ### Data Structure
  21. Property | Type | Usage
  22. --- | --- | ---
  23. data | `Array<BubbleDataObject>` | The data to plot as bubbles. See [Data format](#bubble-chart-data-format)
  24. label | `String` | The label for the dataset which appears in the legend and tooltips
  25. backgroundColor | `Color Array<Color>` | The fill color of the bubbles.
  26. borderColor | `Color or Array<Color>` | The stroke color of the bubbles.
  27. borderWidth | `Number or Array<Number>` | The stroke width of bubble in pixels.
  28. hoverBackgroundColor | `Color or Array<Color>` | The fill color of the bubbles when hovered.
  29. hoverBorderColor | `Color or Array<Color>` | The stroke color of the bubbles when hovered.
  30. hoverBorderWidth | `Number or Array<Number>` | The stroke width of the bubbles when hovered.
  31. hoverRadius | `Number or Array<Number>` | Additional radius to add to data radius on hover.
  32. An example data object using these attributes is shown below. This example creates a single dataset with 2 different bubbles.
  33. ```javascript
  34. var data = {
  35. datasets: [
  36. {
  37. label: 'First Dataset',
  38. data: [
  39. {
  40. x: 20,
  41. y: 30,
  42. r: 15
  43. },
  44. {
  45. x: 40,
  46. y: 10,
  47. r: 10
  48. }
  49. ],
  50. backgroundColor:"#FF6384",
  51. hoverBackgroundColor: "#FF6384",
  52. }]
  53. };
  54. ```
  55. ### Data Object
  56. Data for the bubble chart is passed in the form of an object. The object must implement the following interface. It is important to note that the radius property, `r` is **not** scaled by the chart. It is the raw radius in pixels of the bubble that is drawn on the canvas.
  57. ```javascript
  58. {
  59. // X Value
  60. x: <Number>,
  61. // Y Value
  62. y: <Number>,
  63. // Radius of bubble. This is not scaled.
  64. r: <Number>
  65. }
  66. ```
  67. ### Chart Options
  68. The bubble chart has no unique configuration options. To configure options common to all of the bubbles, the point element options are used.
  69. For example, to give all bubbles a 1px wide black border, the following options would be used.
  70. ```javascript
  71. new Chart(ctx,{
  72. type:"bubble",
  73. options: {
  74. elements: {
  75. points: {
  76. borderWidth: 1,
  77. borderColor: 'rgb(0, 0, 0)'
  78. }
  79. }
  80. }
  81. });
  82. ```
  83. We can also change the default values for the Bubble chart type. Doing so will give all bubble charts created after this point the new defaults. The default configuration for the bubble chart can be accessed at `Chart.defaults.bubble`.