You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stacked_and_mixed.md 2.7 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #### Mixed Bar/Line Chart
  2. As we have seen, chart can have [multiple datasets](/basic/basic_chart?id=adding-more-datasets). Each dataset can also have a different `chartType`, which if specified, should accompany the `type` property set to `axis-mixed`.
  3. ```js
  4. data: {
  5. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  6. datasets: [
  7. {
  8. name: "Dataset 1",
  9. values: [18, 40, 30, 35, 8, 52, 17, -4],
  10. chartType: 'bar'
  11. },
  12. {
  13. name: "Dataset 2",
  14. values: [30, 50, -10, 15, 18, 32, 27, 14],
  15. chartType: 'line'
  16. }
  17. ]
  18. },
  19. type: 'axis-mixed'
  20. ```
  21. This allows for creation of mixed axis chart. It is recommended to list the bar datasets before the line ones to avoid overlapping.
  22. <chart-demo data="mixed-1" v-bind:config="{
  23. type: 'axis-mixed',
  24. height: 200,
  25. colors:['light-green', 'green']
  26. }">
  27. </chart-demo>
  28. All the `lineOptions` and `barOptions` apply to mix and match datasets as well.
  29. <chart-demo data="mixed-2" v-bind:config="{
  30. type: 'axis-mixed',
  31. height: 240,
  32. colors:['light-green', 'green', 'blue'],
  33. lineOptions: {
  34. dotSize: 4
  35. },
  36. barOptions: {
  37. spaceRatio: 0.4
  38. },
  39. }"
  40. v-bind:options="[
  41. {
  42. name: 'barOptions',
  43. path: ['barOptions', 'spaceRatio'],
  44. type: 'number',
  45. numberOptions: { min: 0.1, max: 1.9, step: 0.1 },
  46. activeState: 0.4
  47. },
  48. {
  49. name: 'lineOptions',
  50. path: ['lineOptions', 'dotSize'],
  51. type: 'number',
  52. numberOptions: { min: 3, max: 10, step: 1 },
  53. activeState: 4
  54. }
  55. ]">
  56. </chart-demo>
  57. Infact, one of the bar options is actually dependent on multiple datasets.
  58. #### Stacked Bar Chart
  59. Unlike lines, bars have two ways to show multiple data point values: adjacent or stacked bars. Stacked bar charts are similar to area charts, being useful for comparisions of similar trends. The property [`stacked`]() in `barOptions` renders a stacked bar chart instead of the default adjacent bars:
  60. ```js
  61. barOptions: {
  62. stacked: 1 // default 0, i.e. adjacent
  63. }
  64. ```
  65. <chart-demo data="bar-composite-data" v-bind:config="{
  66. type: 'bar',
  67. height: 240,
  68. colors:['blue', 'green', 'light-green'],
  69. barOptions: {
  70. spaceRatio: 0.4,
  71. stacked: 1
  72. },
  73. }"
  74. v-bind:options="[
  75. {
  76. name: 'barOptions',
  77. path: ['barOptions', 'stacked'],
  78. type: 'Boolean',
  79. states: { 'Stacked': 1, 'Adjacent': 0 },
  80. activeState: 1
  81. }
  82. ]">
  83. </chart-demo>
  84. In [Aggregation Charts]() however, instead of being rendered individually, each data point in aggregated accross every dataset. We'll cover those next.