Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Link plotly_legendclick between several charts

Hi:

Would like to ask if someone knows a way to link the plotly_legendclick event between several independent plots (with independent, I mean there are not subplots).

An image

Basically I want to hide/show the same trace index in all charts, when I click on a legend element.

If I click “Sim 1” in a chart, the same trace has to be hidden/shown in the other charts.

Thank you!

Ok, just found how to make this…

	plotTarget.on('plotly_legendclick', function(ev){
		var isoTarget = document.getElementById("isotherm");
		var etcTarget = document.getElementById("etc");
		if (typeof plotTarget.data[ev.curveNumber].visible ==="undefined"){
			plotTarget.data[ev.curveNumber].visible='legendonly';
			isoTarget.data[ev.curveNumber].visible='legendonly';
			etcTarget.data[ev.curveNumber].visible='legendonly';
		}
		else if (typeof plotTarget.data[ev.curveNumber].visible !=="undefined"){
			plotTarget.data[ev.curveNumber].visible=undefined;
			isoTarget.data[ev.curveNumber].visible=undefined;
			etcTarget.data[ev.curveNumber].visible=undefined;
		}

		Plotly.redraw(plotTarget);
		Plotly.redraw(isoTarget);
		Plotly.redraw(etcTarget);
		return false;
});