amCharts-标签中的多个超级链接

时间:2020-06-29 13:38:46

标签: amcharts

是否可以在同一标签中包含多个链接?我希望能够单击“数据一”或“数据二”,并定向到不同的URL。

var sourceLabel = chart.createChild(am4core.Label);
sourceLabel.text = "Source: Date one & Data Two";
sourceLabel.align = "right";
sourceLabel.interactionsEnabled = true;
sourceLabel.url = "https://data-one.html";

1 个答案:

答案 0 :(得分:1)

如果使用html而不是text,则可以在同一标签中有两个链接:

sourceLabel.html = '<a href="path/to/data-one.html">Data One</a> &amp; <a href="path/to/data-two.html">Data Two</a>'

如果您不想使用html,那么唯一的选择就是创建两个单独的标签。

var chart = am4core.create("chartdiv", am4charts.XYChart);
var sourceLabel = chart.createChild(am4core.Label);
sourceLabel.html = '<a href="path/to/data-one.html">Data One</a> &amp; <a href="path/to/data-two.html">Data Two </a>'

chart.data = [{
  "category": "Research",
  "value": 450
}, {
  "category": "Marketing",
  "value": 1200
}, {
  "category": "Distribution",
  "value": 1850
}];

// Create axes
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;

var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = "value";
series.dataFields.categoryX = "category";
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv" style="width: 100%; height: 300px;"></div>

相关问题