I'm unable to get a hyperlink to this donut chart in amcharts4. I made it successfully using amcharts 3 but am not getting it in amcharts4.
Please let me know what I am doing wrong.
I also referred to another documentation but was unable to get help from it.
Here is my script:
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()
Here is the HTML Part:
<div id="chartdiv"></div>
And The Css
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
You need to use property binding and bind the Slice
's url
property to the "url"
key in your data, e.g.
series.slices.template.propertyFields.url = "url";
series.slices.template.urlTarget = "_blank";
Demo:
https://codepen.io/team/amcharts/pen/6709f9e96d952ee15adfce67dde2ae8f
If "url"
is present in the data, the slice will have their mouse cursor change to a pointer on hover and clicking it will take you to a link in a new window.