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

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

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 -->

Highcharts.chart(&#39;container&#39;, {
    chart: {
        height: 600,
        inverted: true
    },

    title: {
        text: &#39;Highcharts Org Chart&#39;
    },

    accessibility: {
        point: {
            descriptionFormatter: function (point) {
                var nodeName = point.toNode.name,
                    nodeId = point.toNode.id,
                    nodeDesc = nodeName === nodeId ? nodeName : nodeName + &#39;, &#39; + nodeId,
                    parentDesc = point.fromNode.id;
                return point.index + &#39;. &#39; + nodeDesc + &#39;, reports to &#39; + parentDesc + &#39;.&#39;;
            }
        }
    },

    series: [{
        type: &#39;organization&#39;,
        name: &#39;Highsoft&#39;,
        keys: [&#39;from&#39;, &#39;to&#39;],
        data: [
            [&#39;Shareholders&#39;, &#39;Board&#39;],
            [&#39;Board&#39;, &#39;CEO&#39;],
            [&#39;CEO&#39;, &#39;CTO&#39;],
            [&#39;CEO&#39;, &#39;CPO&#39;],
            [&#39;CEO&#39;, &#39;CSO&#39;],
            [&#39;CEO&#39;, &#39;HR&#39;],
            [&#39;CTO&#39;, &#39;Product&#39;],
            [&#39;CTO&#39;, &#39;Web&#39;],
            [&#39;CSO&#39;, &#39;Sales&#39;],
            [&#39;HR&#39;, &#39;Market&#39;],
            [&#39;CSO&#39;, &#39;Market&#39;],
            [&#39;HR&#39;, &#39;Market&#39;],
            [&#39;CTO&#39;, &#39;Market&#39;]
        ],
        levels: [{
            level: 0,
            color: &#39;silver&#39;,
            dataLabels: {
                color: &#39;black&#39;
            },
            height: 25
        }, {
            level: 1,
            color: &#39;silver&#39;,
            dataLabels: {
                color: &#39;black&#39;
            },
            height: 25
        }, {
            level: 2,
            color: &#39;#980104&#39;
        }, {
            level: 4,
            color: &#39;#359154&#39;
        }],
        nodes: [{
            id: &#39;Shareholders&#39;
        }, {
            id: &#39;Board&#39;
        }, {
            id: &#39;CEO&#39;,
            title: &#39;CEO&#39;,
            name: &#39;Atle Sivertsen&#39;,
            image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2022/06/30081411/portrett-sorthvitt.jpg&#39;
        }, {
            id: &#39;HR&#39;,
            title: &#39;CFO&#39;,
            name: &#39;Anne Jorunn Fj&#230;restad&#39;,
            color: &#39;#007ad0&#39;,
            image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131210/Highsoft_04045_.jpg&#39;
        }, {
            id: &#39;CTO&#39;,
            title: &#39;CTO&#39;,
            name: &#39;Christer Vasseng&#39;,
            image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131120/Highsoft_04074_.jpg&#39;
        }, {
            id: &#39;CPO&#39;,
            title: &#39;CPO&#39;,
            name: &#39;Torstein H&#248;nsi&#39;,
            image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131213/Highsoft_03998_.jpg&#39;
        }, {
            id: &#39;CSO&#39;,
            title: &#39;CSO&#39;,
            name: &#39;Anita Nesse&#39;,
            image: &#39;https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131156/Highsoft_03834_.jpg&#39;
        }, {
            id: &#39;Product&#39;,
            name: &#39;Product developers&#39;
        }, {
            id: &#39;Web&#39;,
            name: &#39;Web devs, sys admin&#39;
        }, {
            id: &#39;Sales&#39;,
            name: &#39;Sales team&#39;
        }, {
            id: &#39;Market&#39;,
            name: &#39;Marketing team&#39;,
            column: 5
        }],
        colorByPoint: false,
        color: &#39;#007ad0&#39;,
        dataLabels: {
            color: &#39;white&#39;
        },
        borderColor: &#39;white&#39;,
        nodeWidth: 65
    }],
    tooltip: {
        outside: false
    },
    exporting: {
        allowHTML: true,
        sourceWidth: 800,
        sourceHeight: 600
    }

});

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

.highcharts-figure,
.highcharts-data-table table {
    min-width: 360px;
    max-width: 800px;
    margin: 1em auto;
}

.highcharts-data-table table {
    font-family: Verdana, sans-serif;
    border-collapse: collapse;
    border: 1px solid #ebebeb;
    margin: 10px auto;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}

.highcharts-data-table th {
    font-weight: 600;
    padding: 0.5em;
}

.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
    padding: 0.5em;
}

.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}

.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

#container h4 {
    text-transform: none;
    font-size: 14px;
    font-weight: normal;
}

#container p {
    font-size: 13px;
    line-height: 16px;
}

@media screen and (max-width: 600px) {
    #container h4 {
        font-size: 2.3vw;
        line-height: 3vw;
    }

    #container p {
        font-size: 2.3vw;
        line-height: 3vw;
    }
}

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

&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/sankey.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/organization.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/exporting.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/accessibility.js&quot;&gt;&lt;/script&gt;

&lt;figure class=&quot;highcharts-figure&quot;&gt;
    &lt;div id=&quot;container&quot;&gt;&lt;/div&gt;
    &lt;p class=&quot;highcharts-description&quot;&gt;
        Organization charts are a common case of hierarchical network charts,
        where the parent/child relationships between nodes are visualized.
        Highcharts includes a dedicated organization chart type that streamlines
        the process of creating these types of visualizations.
    &lt;/p&gt;
&lt;/figure&gt;

<!-- end snippet -->

答案1

得分: 1

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

节点:

{
  id: 'C',
  key: 'Cinnamon',
  events: {
    click() {
      location.href = 'https://en.wikipedia.org/wiki/' +
        this.options.key;
    }
  }
}

演示:
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.

nodes: [
		{
      id: &#39;C&#39;,
      key: &#39;Cinnamon&#39;,
      events: {
        click() {
          location.href = &#39;https://en.wikipedia.org/wiki/&#39; +
            this.options.key;
        }
      }
    },

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:

确定