Chart/api/legend.ts

  1. /**
  2. * Copyright (c) 2017 ~ present NAVER Corp.
  3. * billboard.js project is licensed under the MIT license
  4. */
  5. /**
  6. * Define legend
  7. * @ignore
  8. */
  9. const legend = {
  10. /**
  11. * Show legend for each target.
  12. * - **NOTE:** Legend APIs aren't supported for `treemap` type.
  13. * @function legend․show
  14. * @instance
  15. * @memberof Chart
  16. * @param {string|Array} targetIds
  17. * - If targetIds is given, specified target's legend will be shown.
  18. * - If only one target is the candidate, String can be passed.
  19. * - If no argument is given, all of target's legend will be shown.
  20. * @example
  21. * // Show legend for data1.
  22. * chart.legend.show("data1");
  23. *
  24. * // Show legend for data1 and data2.
  25. * chart.legend.show(["data1", "data2"]);
  26. *
  27. * // Show all legend.
  28. * chart.legend.show();
  29. */
  30. show: function(targetIds?: string | string[]): void {
  31. const $$ = this.internal;
  32. $$.showLegend($$.mapToTargetIds(targetIds));
  33. $$.updateAndRedraw({withLegend: true});
  34. },
  35. /**
  36. * Hide legend for each target.
  37. * @function legend․hide
  38. * @instance
  39. * @memberof Chart
  40. * @param {string|Array} targetIds
  41. * - If targetIds is given, specified target's legend will be hidden.
  42. * - If only one target is the candidate, String can be passed.
  43. * - If no argument is given, all of target's legend will be hidden.
  44. * @example
  45. * // Hide legend for data1.
  46. * chart.legend.hide("data1");
  47. *
  48. * // Hide legend for data1 and data2.
  49. * chart.legend.hide(["data1", "data2"]);
  50. *
  51. * // Hide all legend.
  52. * chart.legend.hide();
  53. */
  54. hide: function(targetIds?: string | string[]): void {
  55. const $$ = this.internal;
  56. $$.hideLegend($$.mapToTargetIds(targetIds));
  57. $$.updateAndRedraw({withLegend: true});
  58. }
  59. };
  60. export default {legend};