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.

basic_chart.md 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ## What is it
  2. A chart is generally a 2D rendition of data. For example, for a set of 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. Plug that in with a type `bar`, a 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. <div class="demo" id="bar-basic-1"></div>
  21. And similarly, a `line` chart:
  22. ```js
  23. type:'line'
  24. ```
  25. <div class="demo" id="line-basic-1"></div>
  26. ## Tweaks
  27. Axes lines are configurable. By default they are long `span`ning lines, but can also be short `tick`s:`
  28. ```js
  29. axisOptions: {
  30. xAxisMode: 'tick' // default: 'span'
  31. },
  32. ```
  33. <div class="demo" id="bar-axis-tick"></div>
  34. The bar <b>width</b> can be set by defining the <b>ratio of the space</b> between bars to the bar width.
  35. ```js
  36. barOptions: {
  37. spaceRatio: 0.2 // default: 1
  38. },
  39. ```
  40. <div class="demo" id="bar-barwidth"></div>
  41. So can the <b>dot size</b> on a line graph, with the `dotSize` property in `lineOptions`.
  42. ```js
  43. lineOptions: {
  44. dotSize: 8 // default: 4
  45. },
  46. ```
  47. <div class="demo" id="line-dotsize"></div>
  48. Next up, we'll discover how multiple datasets can behave in different charts.