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.

пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ## Axis chart: what is it
  2. An axis chart is generally a 2D rendition of data, where a set of values corresponds to every point in a dataset. That's why, data is the most important component for a chart. For example, for some values across items, the data could look like:
  3. ```js
  4. data = {
  5. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  6. datasets: [
  7. { values: [18, 40, 30, 35, 8, 52, 17, -4] }
  8. ]
  9. }
  10. ```
  11. Rendering it doesn't require much more that that. Plug the data in with a [type]() `bar`, with an optional [color]() and [height]():
  12. ```js
  13. new frappe.Chart( "#chart", {
  14. data: data,
  15. type: 'bar',
  16. height: 140,
  17. colors: ['red']
  18. });
  19. ```
  20. <chart-demo
  21. data="0"
  22. v-bind:config="{ type: 'bar', height: 140, colors:['red'] }">
  23. </chart-demo>
  24. And similarly, a `line` chart is data-wise homomorphic to a bar chart:
  25. ```js
  26. type:'line'
  27. ```
  28. <chart-demo
  29. data="0"
  30. v-bind:config="{ type: 'line', height: 140, colors:['red'] }">
  31. </chart-demo>
  32. ## Adding more datasets
  33. A chart can have multiple datasets. In an axis chart, every dataset is represented individually.
  34. ```js
  35. data: {
  36. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  37. datasets: [
  38. { name: "Dataset 1", values: [18, 40, 30, 35, 8, 52, 17, -4] },
  39. { name: "Dataset 2", values: [30, 50, -10, 15, 18, 32, 27, 14] }
  40. ]
  41. }
  42. ```
  43. Notice that this case demonstrates why the `colors` option is an array. We'll see more about it ahead.
  44. <chart-demo data="1" v-bind:config="{
  45. type: 'line',
  46. height: 200,
  47. colors:['green', 'light-green']
  48. }"
  49. v-bind:options="[
  50. {
  51. name: 'type',
  52. path: ['type'],
  53. type: 'string',
  54. states: { 'Line': 'line', 'Bar': 'bar' },
  55. activeState: 'Mixed'
  56. }
  57. ]">
  58. </chart-demo>
  59. ## Responsiveness
  60. Frappe Charts are responsive, as they rerender all the data in the current available container width. To demonstrate, let's take the example of setting the [bar width]() for bar charts.
  61. In order to set the bar width, instead of defining it and the space between the bars independently, we simply define the <b>ratio of the space</b> between bars to the bar width. The chart then adjusts the actual size proportional to the chart container.
  62. ```js
  63. barOptions: {
  64. spaceRatio: 0.2 // default: 1
  65. },
  66. ```
  67. Try resizing the window to see the effect, with different ratio values.
  68. <chart-demo data="2" v-bind:config="{
  69. type: 'bar',
  70. height: 140,
  71. colors: ['orange'],
  72. axisOptions: { xAxisMode: 'tick' },
  73. barOptions: { spaceRatio: 0.2 },
  74. }"
  75. v-bind:options="[
  76. {
  77. name: 'barOptions',
  78. path: ['barOptions', 'spaceRatio'],
  79. type: 'number',
  80. numberOptions: { min: 0.1, max: 1.9, step: 0.1 },
  81. activeState: 0.2
  82. }
  83. ]">
  84. </chart-demo>
  85. ## More Tweaks
  86. Axis lines define a chart presentation. By default they are long `span`ning lines, but to give prominence to data points, X and/or Y axes can also be short `tick`s:
  87. ```js
  88. axisOptions: {
  89. xAxisMode: 'tick' // default: 'span'
  90. },
  91. ```
  92. <chart-demo
  93. data="2"
  94. v-bind:config="{
  95. type: 'bar',
  96. height: 140,
  97. colors:['blue'],
  98. axisOptions: { xAxisMode: 'tick' }
  99. }">
  100. </chart-demo>
  101. Just like bar width, we can set the <b>dot size</b> on a line graph, with the [`dotSize`]() property in [`lineOptions`]().
  102. ```js
  103. lineOptions: {
  104. dotSize: 8 // default: 4
  105. },
  106. ```
  107. <chart-demo data="2" v-bind:config="{
  108. type: 'line',
  109. height: 140,
  110. colors:['orange'],
  111. axisOptions: { xAxisMode: 'tick' },
  112. lineOptions: { dotSize: 8 }
  113. }"
  114. v-bind:options="[
  115. {
  116. name: 'lineOptions',
  117. path: ['lineOptions', 'dotSize'],
  118. type: 'number',
  119. numberOptions: { min: 3, max: 10, step: 1 },
  120. activeState: 8
  121. }
  122. ]">
  123. </chart-demo>
  124. These were some of the basic toggles to a chart; there are quite a few line options to go with, particularly to create [regions](). We'll look at those in next section.