0

I am trying to replicate the pie chart behaviour from this v4 tutorial on amCharts v5 with no luck:

https://www.amcharts.com/docs/v4/tutorials/one-pulled-slice-per-pie-chart/

The v4 code does not work on v5 (nor getting error). I have debugged it and it loops through the slices, but there is no more "isActive" property, and have not found any other similar property or method to get or set the slice state.

I have already searched in offical docs but found nothing. Seems v5 is lacking some v4 features... anyone accomplished to limit only 1 selected slice per chart?

Thanks in advance.

1 Answers1

0

From official amCharts tutorial "One pulled slice per pie series":

... so whenever a slice is pulled out, it becomes "active" (it's "active" setting is set to true). And vice versa, setting it to false will make the slice pop back into its place.

Also, when a slice (or any other object for that matter) is clicked/tapped, it generates a "click" event. If there's an event handler defined, it is executed.

Let's use these two bits of code to implement our task:

series.slices.template.events.on("click", function(ev) {
  series.slices.each(function(slice) {
    if (slice != ev.target && slice.get("active")) {
      slice.set("active", false);
    }
  })
});

CodePen example: https://codepen.io/team/amcharts/pen/dyZzQLJ

martynasma
  • 8,542
  • 2
  • 28
  • 45