AmCharts 4 圆环图 - 自定义超链接 URL
AmCharts 4 Donut Graph - HyperLink for Custom URL
我无法获得指向 this donut chart in amcharts4. I made it successfully using 的超链接,但我无法在 amcharts4 中获得它。
请让我知道我做错了什么。
我还提到了另一个 但无法从中获得帮助。
这是我的脚本:
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>
您需要对数据中的 "url"
键使用 property binding and bind the Slice
's url
property,例如
series.slices.template.propertyFields.url = "url";
series.slices.template.urlTarget = "_blank";
演示:
https://codepen.io/team/amcharts/pen/6709f9e96d952ee15adfce67dde2ae8f
如果 "url"
出现在数据中,切片将在鼠标悬停时将其鼠标光标更改为指针,单击它将带您到新 [=26= 中的 link ].
series.slices.template.events.on("hit", function(ev) {
var url=ev.target.dataItem.dataContext.url
console.log('currentTargt',url)
window.location=url
});
series.targetUrl="_blank";
上面的东西对我也有用。
我无法获得指向 this donut chart in amcharts4. I made it successfully using
请让我知道我做错了什么。
我还提到了另一个
这是我的脚本:
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>
您需要对数据中的 "url"
键使用 property binding and bind the Slice
's url
property,例如
series.slices.template.propertyFields.url = "url";
series.slices.template.urlTarget = "_blank";
演示:
https://codepen.io/team/amcharts/pen/6709f9e96d952ee15adfce67dde2ae8f
如果 "url"
出现在数据中,切片将在鼠标悬停时将其鼠标光标更改为指针,单击它将带您到新 [=26= 中的 link ].
series.slices.template.events.on("hit", function(ev) {
var url=ev.target.dataItem.dataContext.url
console.log('currentTargt',url)
window.location=url
});
series.targetUrl="_blank";
上面的东西对我也有用。