To achieve this, you can utilize the active
state feature:
var activeState = series.columns.template.states.create("active");
activeState.properties.fill = am4core.color('red');
By incorporating the hit
event, you can designate columns as active. To ensure smooth transitions, you can reset the previous selection before activating a new column:
var currentActive;
series.columns.template.events.on("hit", function(ev) {
if (currentActive) {
currentActive.isActive = false;
}
currentActive = ev.target;
currentActive.isActive = true;
});
If you prefer not to store the last choice, you can deactivate all columns before selecting a new one:
series.columns.template.events.on("hit", function(ev) {
series.columns.values.forEach(c => c.isActive = false);
ev.target.isActive = true;
});
For the option to deselect all columns, you can enhance the second method like so:
series.columns.template.events.on("hit", function(ev) {
series.columns.values
.filter(c => c !== ev.target)
.forEach(c => c.isActive = false);
ev.target.isActive = !ev.target.isActive;
});
You can view a demonstration of this functionality on CodePen. Simply customize the code snippet to suit your requirements.