Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*Dynamic* styling of a single marker #4352

Closed
ccamero8 opened this issue Nov 14, 2019 · 2 comments
Closed

*Dynamic* styling of a single marker #4352

ccamero8 opened this issue Nov 14, 2019 · 2 comments

Comments

@ccamero8
Copy link

Related to issue#144.

In the linked issue above, a solution was provided to style a single marker on a line. However, the identifier for the marker seems to be hardcoded.

To be more specific, the solution is to use restyle like this:
Plotly.restyle(gd, {'marker.color[23]': 'red'}, null, [0])

This does in fact work, and changes the 23rd index marker to red. However, if I change the code to something like this:
let dynamicallyFoundIndex = 14;
let str = "marker.color[" + dynamicallyFoundIndex + "]";
Plotly.restyle(gd, {str: 'red'}, null, [0])

Nothing happens. No errors in the console, and no markers' styling changes.

Hopefully I'm overlooking something simple here, but I haven't been able to get this to work. Any help is appreciated. Thanks!

@alexcjohnson
Copy link
Collaborator

alexcjohnson commented Nov 14, 2019

That will attempt to restyle the attribute literally 'str'
If you're using es6:

Plotly.restyle(gd, {[str]: 'red'}, null, [0])

Or with es5:

var dynamicallyFoundIndex = 14;
var str = "marker.color[" + dynamicallyFoundIndex + "]";
var editObj = {};
editObj[str] = 'red';
Plotly.restyle(gd, editObj, null, [0]);

@etpinard
Copy link
Contributor

etpinard commented Nov 18, 2019

This one appears resolved. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants