# Does plotly.js scatter/line graph handle point selection?

**URL:** <https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237>\
**Category:** plotly.js\
**Created:** [December 15, 2015, 11:49pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237 "2015-12-15T23:49:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://community.plotly.com/u/kevin)\
**Post date:** [December 15, 2015, 11:49pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/1 "2015-12-15T23:49:37Z")

</div>

Hi plotyly devs and community!

I want to use plotly in an interactive line graph and needs point selection as a part of the interaction. So far plotly does not highlight the selected points. Is there a way to enable this?

For example, when a point on a line chart is clicked, it will display in different marker symbol / color. Or is there a fast way to achieve this?

Thanks!  
Kevin

---

<div class="post-metadata">

**Author:** ![Miklos](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Miklos](https://community.plotly.com/u/Miklos)\
**Post date:** [December 16, 2015, 5:24pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/2 "2015-12-16T17:24:53Z")

</div>

Hi Kevin,

Plotly exposes click and hover events, so you can do things like this:

```auto
var myDiv = document.getElementById('my-div');

Plotly.plot(myDiv, [{ x: [1,2,3], y: [5,7,2] }], {});

myDiv.on('plotly_click', function(evt){
  // Do something with the data from the event,
  // for example, calling `Plotly.restyle`
});

```

There’s some more examples [here](https://plot.ly/javascript/click-events/) too!

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://community.plotly.com/u/kevin)\
**Post date:** [December 16, 2015, 5:42pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/3 "2015-12-16T17:42:30Z")

</div>

Hi,

Thanks very much for the response!

Somehow I don’t find a way to highlight one point after selection. The ‘restyle’ function only allows restyling one entire trace. I want to select two points from same time series and mark the points on the graph. So is the ‘select + highlight point’ effect possible in Plotly?

The Google charts has something I described. When you click on the chart it will mark the point:

[https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart](https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart)

Besides the example in the link you mentioned is not working on Firefox 39.0 or Chrome 47. Chrome complains with the following errors:

Uncaught TypeError: Cannot read property ‘points’ of undefinedn @ plotly-latest.min.js:34  
pen.js:16

Thanks!  
Regards,  
Kevin

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [December 16, 2015, 6:55pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/4 "2015-12-16T18:55:02Z")

</div>

@kevin

You need to wrap the value attribute in `Plotly.restyle` with an extra `[]` to modify each point in a trace.

See example here: [http://codepen.io/etpinard/pen/QyLbqY](http://codepen.io/etpinard/pen/QyLbqY)

That is, `Plotly.restyle('graph', 'marker.color', ['red', 'green','blue'])` restyles the first trace in red, the second in green and the third in blue.

Whereas, `Plotly.restyle('graph', 'marker.color', [['red', 'green','blue']])` restyles the points in the first trace.

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://community.plotly.com/u/kevin)\
**Post date:** [December 16, 2015, 8:49pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/5 "2015-12-16T20:49:29Z")

</div>

Thanks. I did not notice that before. I’ll give a shot.

Thanks very much for the advice!

---

<div class="post-metadata">

**Author:** ![pscanlon1](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@pscanlon1](https://community.plotly.com/u/pscanlon1)\
**Post date:** [March 3, 2016, 5:36pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/6 "2016-03-03T17:36:21Z")

</div>

Hi, it seems that most charts, if i set hovermode:false, in the layout, that the click event does not fire.

My intention is that I am trying to NOT show your tooltip, but get access to the point data on click.

If i have hovermode:‘none’, even, then the click event registers, BUT, it shows an empty tooltip.

Thanks!

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [March 3, 2016, 10:22pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/7 "2016-03-03T22:22:51Z")

</div>

> [@pscanlon1](#):
>
> if i set hovermode:false, in the layout, that the click event does not fire.

Looks like you discovered a bug. Thanks for writing in!

Please subscribe to [Falsy hovermode and/or hoverinfo should not disabe click event data · Issue #313 · plotly/plotly.js · GitHub](https://github.com/plotly/plotly.js/issues/313) for the latest development.

---

<div class="post-metadata">

**Author:** ![MarkvDijk](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@MarkvDijk](https://community.plotly.com/u/MarkvDijk)\
**Post date:** [November 24, 2017, 7:01pm UTC](https://community.plotly.com/t/does-plotly-js-scatter-line-graph-handle-point-selection/237/8 "2017-11-24T19:01:34Z")

</div>

how would you apply this in R with shiny? I would love to restyle the color palette based on a users choice for a new color, and apply a new pallette to all traces using a modification of the Plotly.restyle(‘graph’, ‘marker.color’, [[‘red’, ‘green’,‘blue’]] approach
