gpt4 book ai didi

javascript - AmCharts 4 donut chart - 自定义 URL 的超链接

转载 作者:行者123 更新时间:2023-12-03 07:06:30 29 4
gpt4 key购买 nike

我无法获得指向 this 的超链接amcharts4中的 donut chart 。我成功使用 amcharts 3但我没有在 amcharts4 中得到它。

请让我知道我做错了什么。

我还提到了另一个 documentation但无法从中获得帮助。

这是我的脚本:

am4core.ready(function() {

// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

var chart = am4core.create("chartdiv", am4charts.PieChart3D);
chart.hiddenState.properties.opacity = 0; // this creates initial fade-in

chart.data = [
{
country: "India",
litres: 501.9,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
},
{
country: "Czech Republic",
litres: 301.9,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
},
{
country: "China",
litres: 201.1,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
},
{
country: "Germany",
litres: 165.8,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
},
{
country: "Australia",
litres: 139.9,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
},
{
country: "Japan",
litres: 128.3,
url:"amcharts.com/docs/v4/tutorials/clickable-links-in-tooltips/"
}
];


chart.innerRadius = am4core.percent(40);
chart.depth = 120;

chart.legend = new am4charts.Legend();

var series = chart.series.push(new am4charts.PieSeries3D());
series.dataFields.value = "litres";
series.dataFields.depthValue = "litres";
series.dataFields.category = "country";
series.slices.template.cornerRadius = 5;
series.colors.step = 3;
series.urlField= "url";
series.urlTarge= "_blank"

}); // end am4core.ready()

这是 HTML 部分:
<div id="chartdiv"></div>

和CSS
<style>
#chartdiv {
width: 100%;
height: 500px;
}

</style>

最佳答案

您需要使用 property binding并绑定(bind)Slice url property"url"输入您的数据,例如

series.slices.template.propertyFields.url = "url";
series.slices.template.urlTarget = "_blank";

演示:

https://codepen.io/team/amcharts/pen/6709f9e96d952ee15adfce67dde2ae8f

如果 "url"存在于数据中,切片将鼠标光标变为悬停指针,单击它将带您到新窗口中的链接。

关于javascript - AmCharts 4 donut chart - 自定义 URL 的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575698/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com