Chart/api/group.ts

  1. /**
  2. * Copyright (c) 2017 ~ present NAVER Corp.
  3. * billboard.js project is licensed under the MIT license
  4. */
  5. import {isUndefined} from "../../module/util";
  6. export default {
  7. /**
  8. * Update groups for the targets.
  9. * @function groups
  10. * @instance
  11. * @memberof Chart
  12. * @param {Array} groups This argument needs to be an Array that includes one or more Array that includes target ids to be grouped.
  13. * @returns {Array} Grouped data names array
  14. * @example
  15. * // data1 and data2 will be a new group.
  16. * chart.groups([
  17. * ["data1", "data2"]
  18. * ]);
  19. */
  20. groups<T = string[][]>(groups: T): T {
  21. const $$ = this.internal;
  22. const {config} = $$;
  23. if (isUndefined(groups)) {
  24. return config.data_groups;
  25. }
  26. config.data_groups = groups;
  27. $$.redraw();
  28. return config.data_groups;
  29. }
  30. };