Skip to content

Commit 48aac3d

Browse files
authored
Update 2018-08-06-order6_legendclick_event.html
1 parent 1a2f9bb commit 48aac3d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

_posts/plotly_js/chart-events/events/2018-08-06-order6_legendclick_event.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
`plotly_legendclick` and `plotly_legenddoubleclick` allow customization of the plotly legend. The default behaviour of `plotly_legendclick` is to hide a trace and the default behavior of `plotly_legenddoubleclick` is to select one trace and hide all the others.
1111
We can add to the default behaviour by creating a new `plotly_legendclick` event with a function of our choice. We can also disable the default behaviour by creating a function that returns `false`. In the example below, we do both in order to create a `plotly_legendclick` event which changes the marker color back to black instead of erasing the trace.
1212
---
13-
1413
var myPlot = document.getElementById('myDiv'),
1514
x = [1, 2, 3, 4, 5, 6],
1615
y = [1, 2, 3, 2, 3, 4],
1716
y2 = [1, 4, 7, 6, 1, 5],
18-
colors = [['#00000','#00000','#00000','#00000','#00000','#00000'],
19-
['#00000','#00000','#00000','#00000','#00000','#00000']],
17+
colors = [['#5C636E','#5C636E','#5C636E','#5C636E','#5C636E','#5C636E'],
18+
['#393e46','#393e46','#393e46','#393e46','#393e46','#393e46']],
2019
data = [{x:x, y:y, type:'scatter',
21-
mode:'line', line:{ color:'red'},marker:{size:16, color:colors[0]}},
20+
mode:'line', line:{ color:'#5C636E'},marker:{size:16, color:colors[0]}},
2221
{x:x, y:y2, type:'scatter',
23-
mode:'line',line:{ color:'black'}, marker:{size:16, color:colors[1]}}],
22+
mode:'line',line:{ color:'#393e46'}, marker:{size:16, color:colors[1]}}],
2423
layout = {
2524
showlegend: true,
2625
hovermode:'closest',
@@ -44,9 +43,9 @@
4443
});
4544

4645
myPlot.on('plotly_legendclick', function(data){
47-
var trColors = ['#00000','#00000','#00000',
48-
'#00000','#00000','#00000'];
49-
var update = {'marker':{color: trColors, size:16}};
46+
var trColors = [['#5C636E','#5C636E','#5C636E','#5C636E','#5C636E','#5C636E'],
47+
['#393e46','#393e46','#393e46','#393e46','#393e46','#393e46']];
48+
var update = {'marker':{color: trColors[data.curveNumber], size:16}};
5049
Plotly.restyle('myDiv', update,[data.curveNumber]);
5150
return false;
5251
});

0 commit comments

Comments
 (0)