Reputation: 5623
Like this example, how do you add support for redirecting on a url when someone clicks on a slice.
Like on this example.
I have tried doing what the documentation requires:
if (cbSeriesClicked !== undefined) {
pieSeries.events.on("hit", cbSeriesClicked, this);
}
The event fires, but im unable able to figure out where in the chart object the currently selected slice is, or if amcharts 4 supports https://www.amcharts.com/docs/v3/tutorials/linking-chart-columns-custom-urls/
Upvotes: 1
Views: 1166
Reputation: 16012
The AmCharts 4 equivalent is to use propertyFields
on the series/series sub item template, depending on the chart type and set the url
property to match up with the property in your data containing the URL. You can also set urlTarget
to control whether it opens in a new tab or not. For pie charts, you have to set it on the sub item template like so:
//assumes your data contains a property called "url":
var pieSeries = chart.series.push(new am4charts.PieSeries());
// ...
pieSeries.slices.template.propertyFields.url = "url";
pieSeries.slices.template.urlTarget = "_blank";
Upvotes: 3