user42195
user42195

Reputation: 339

How to pass color props by Nivo ResponsiveBar?

I use Nivo's responsive bar. I want to show a bar like the image. And I can do it if I set the colors directly like below . But I can set it by passing the props or set by a function. How can I do it?

<ResponsiveBar
  colors='#0481F8'
/>

enter image description here

const getColor = () => title===A ? '#0481F8' : title===B ? '#F98700'

<ResponsiveBar
  title={title}
  data={data}
  colors={getColor()}
/>

Parent

<Chart color='#0481F8' data=...>

Child

const Chart = ({data, color}) => {

return (
<>
<ResponsiveBar
  data={data}
  colors={color}
/>
</>
)}

Upvotes: 0

Views: 1261

Answers (1)

Abhishek Singh
Abhishek Singh

Reputation: 527

Yes you can set it through props, ResponsiveBar can take multiple colors also. You should use it as,

<Chart color={['#0481F8']} data={..}>

const Chart = ({data, color}) => {

return (
<ResponsiveBar
  data={data}
  colors={color}
/>
)}

Upvotes: 1

Related Questions