将“a”标签添加到Highcharts组织图。

huangapple go评论92阅读模式
英文:

Add "a" tag to Highcharts Org Chart

问题

我想在Highcharts组织图中进行一些更改。我想要将“board”节点更改为“a”标签,以便用户能够单击它。你能帮我吗?如何做到这一点?谢谢你这么多。

英文:

I am going to make some changes in Highcharts Org Chart. I want to add an "a" tag to only one of the nodes of Highcharts Organization Chart ][enter link description here][1]
For example I want to change'board' node to an 'a' tag so the user can be able to click on it. can you please help me How can I do that?
Thank you so much

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. Highcharts.chart(&#39;container&#39;, {
  2. chart: {
  3. height: 600,
  4. inverted: true
  5. },
  6. title: {
  7. text: &#39;Highcharts Org Chart&#39;
  8. },
  9. accessibility: {
  10. point: {
  11. descriptionFormatter: function (point) {
  12. var nodeName = point.toNode.name,
  13. nodeId = point.toNode.id,
  14. nodeDesc = nodeName === nodeId ? nodeName : nodeName + &#39;, &#39; + nodeId,
  15. parentDesc = point.fromNode.id;
  16. return point.index + &#39;. &#39; + nodeDesc + &#39;, reports to &#39; + parentDesc + &#39;.&#39;;
  17. }
  18. }
  19. },
  20. series: [{
  21. type: &#39;organization&#39;,
  22. name: &#39;Highsoft&#39;,
  23. keys: [&#39;from&#39;, &#39;to&#39;],
  24. data: [
  25. [&#39;Shareholders&#39;, &#39;Board&#39;],
  26. [&#39;Board&#39;, &#39;CEO&#39;],
  27. [&#39;CEO&#39;, &#39;CTO&#39;],
  28. [&#39;CEO&#39;, &#39;CPO&#39;],
  29. [&#39;CEO&#39;, &#39;CSO&#39;],
  30. [&#39;CEO&#39;, &#39;HR&#39;],
  31. [&#39;CTO&#39;, &#39;Product&#39;],
  32. [&#39;CTO&#39;, &#39;Web&#39;],
  33. [&#39;CSO&#39;, &#39;Sales&#39;],
  34. [&#39;HR&#39;, &#39;Market&#39;],
  35. [&#39;CSO&#39;, &#39;Market&#39;],
  36. [&#39;HR&#39;, &#39;Market&#39;],
  37. [&#39;CTO&#39;, &#39;Market&#39;]
  38. ],
  39. levels: [{
  40. level: 0,
  41. color: &#39;silver&#39;,
  42. dataLabels: {
  43. color: &#39;black&#39;
  44. },
  45. height: 25
  46. }, {
  47. level: 1,
  48. color: &#39;silver&#39;,
  49. dataLabels: {
  50. color: &#39;black&#39;
  51. },
  52. height: 25
  53. }, {
  54. level: 2,
  55. color: &#39;#980104&#39;
  56. }, {
  57. level: 4,
  58. color: &#39;#359154&#39;
  59. }],
  60. nodes: [{
  61. id: &#39;Shareholders&#39;
  62. }, {
  63. id: &#39;Board&#39;
  64. }, {
  65. id: &#39;CEO&#39;,
  66. title: &#39;CEO&#39;,
  67. name: &#39;Atle Sivertsen&#39;,
  68. image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2022/06/30081411/portrett-sorthvitt.jpg&#39;
  69. }, {
  70. id: &#39;HR&#39;,
  71. title: &#39;CFO&#39;,
  72. name: &#39;Anne Jorunn Fj&#230;restad&#39;,
  73. color: &#39;#007ad0&#39;,
  74. image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131210/Highsoft_04045_.jpg&#39;
  75. }, {
  76. id: &#39;CTO&#39;,
  77. title: &#39;CTO&#39;,
  78. name: &#39;Christer Vasseng&#39;,
  79. image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131120/Highsoft_04074_.jpg&#39;
  80. }, {
  81. id: &#39;CPO&#39;,
  82. title: &#39;CPO&#39;,
  83. name: &#39;Torstein H&#248;nsi&#39;,
  84. image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131213/Highsoft_03998_.jpg&#39;
  85. }, {
  86. id: &#39;CSO&#39;,
  87. title: &#39;CSO&#39;,
  88. name: &#39;Anita Nesse&#39;,
  89. image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131156/Highsoft_03834_.jpg&#39;
  90. }, {
  91. id: &#39;Product&#39;,
  92. name: &#39;Product developers&#39;
  93. }, {
  94. id: &#39;Web&#39;,
  95. name: &#39;Web devs, sys admin&#39;
  96. }, {
  97. id: &#39;Sales&#39;,
  98. name: &#39;Sales team&#39;
  99. }, {
  100. id: &#39;Market&#39;,
  101. name: &#39;Marketing team&#39;,
  102. column: 5
  103. }],
  104. colorByPoint: false,
  105. color: &#39;#007ad0&#39;,
  106. dataLabels: {
  107. color: &#39;white&#39;
  108. },
  109. borderColor: &#39;white&#39;,
  110. nodeWidth: 65
  111. }],
  112. tooltip: {
  113. outside: false
  114. },
  115. exporting: {
  116. allowHTML: true,
  117. sourceWidth: 800,
  118. sourceHeight: 600
  119. }
  120. });

<!-- language: lang-css -->

  1. .highcharts-figure,
  2. .highcharts-data-table table {
  3. min-width: 360px;
  4. max-width: 800px;
  5. margin: 1em auto;
  6. }
  7. .highcharts-data-table table {
  8. font-family: Verdana, sans-serif;
  9. border-collapse: collapse;
  10. border: 1px solid #ebebeb;
  11. margin: 10px auto;
  12. text-align: center;
  13. width: 100%;
  14. max-width: 500px;
  15. }
  16. .highcharts-data-table caption {
  17. padding: 1em 0;
  18. font-size: 1.2em;
  19. color: #555;
  20. }
  21. .highcharts-data-table th {
  22. font-weight: 600;
  23. padding: 0.5em;
  24. }
  25. .highcharts-data-table td,
  26. .highcharts-data-table th,
  27. .highcharts-data-table caption {
  28. padding: 0.5em;
  29. }
  30. .highcharts-data-table thead tr,
  31. .highcharts-data-table tr:nth-child(even) {
  32. background: #f8f8f8;
  33. }
  34. .highcharts-data-table tr:hover {
  35. background: #f1f7ff;
  36. }
  37. #container h4 {
  38. text-transform: none;
  39. font-size: 14px;
  40. font-weight: normal;
  41. }
  42. #container p {
  43. font-size: 13px;
  44. line-height: 16px;
  45. }
  46. @media screen and (max-width: 600px) {
  47. #container h4 {
  48. font-size: 2.3vw;
  49. line-height: 3vw;
  50. }
  51. #container p {
  52. font-size: 2.3vw;
  53. line-height: 3vw;
  54. }
  55. }

<!-- language: lang-html -->

  1. &lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
  2. &lt;script src=&quot;https://code.highcharts.com/modules/sankey.js&quot;&gt;&lt;/script&gt;
  3. &lt;script src=&quot;https://code.highcharts.com/modules/organization.js&quot;&gt;&lt;/script&gt;
  4. &lt;script src=&quot;https://code.highcharts.com/modules/exporting.js&quot;&gt;&lt;/script&gt;
  5. &lt;script src=&quot;https://code.highcharts.com/modules/accessibility.js&quot;&gt;&lt;/script&gt;
  6. &lt;figure class=&quot;highcharts-figure&quot;&gt;
  7. &lt;div id=&quot;container&quot;&gt;&lt;/div&gt;
  8. &lt;p class=&quot;highcharts-description&quot;&gt;
  9. Organization charts are a common case of hierarchical network charts,
  10. where the parent/child relationships between nodes are visualized.
  11. Highcharts includes a dedicated organization chart type that streamlines
  12. the process of creating these types of visualizations.
  13. &lt;/p&gt;
  14. &lt;/figure&gt;

<!-- end snippet -->

答案1

得分: 1

你可以给标题/名称添加href属性,但那样只有文本可点击。如果要使整个节点可点击,请使用点击事件。

节点:

  1. {
  2. id: 'C',
  3. key: 'Cinnamon',
  4. events: {
  5. click() {
  6. location.href = 'https://en.wikipedia.org/wiki/' +
  7. this.options.key;
  8. }
  9. }
  10. }

演示:
https://jsfiddle.net/BlackLabel/Lgq37pjv/

API 参考:
https://api.highcharts.com/highcharts/series.organization.point.events.click

英文:

You can add href attribute to the title/name, but then only the text will be clickable. If you want to make clickable the whole node, use click event.

  1. nodes: [
  2. {
  3. id: &#39;C&#39;,
  4. key: &#39;Cinnamon&#39;,
  5. events: {
  6. click() {
  7. location.href = &#39;https://en.wikipedia.org/wiki/&#39; +
  8. this.options.key;
  9. }
  10. }
  11. },

Demo:
https://jsfiddle.net/BlackLabel/Lgq37pjv/

API Reference:
https://api.highcharts.com/highcharts/series.organization.point.events.click

huangapple
  • 本文由 发表于 2023年4月20日 04:31:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定