'Nivo React Scatterplot - node colors per object key - possible?
Using Nivo React Scatterplot chart I want to specify dot color respective to key value of my data object.
E.g.:
data: [
{ x: 0, y: 3300, average: 3500, status: "sold" },
{ x: 1, y: 3500, average: 3500, status: "forSale" }
]
If status "sold" then red, otherwise green
Scatterpplot doesn't seem to return anything from the color object but serieId string:
colors={(colorObj) => console.log(colorObj)} // returns: serieId: "someString"
You can see a sample here:
https://codesandbox.io/s/scatterplot-custom-layer-iqb2ox
I thought I could use a function in the color, sth like this:
color={(node) => node.status === 'sold' ? 'red' : 'green'}
... but it seems there's nothing I can hook into.
Is there something I'm missing?
Thanks for any tips on how I could achieve this.
Chris
P.S.: there is an answer re. setting individual colors per dot here on SO but that doesn't seem to work anymore
How to Set Individual Point Colors in Nivo Scatterplot for React
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|