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

bar custom color using data label nivo #2489

Closed
gowsi-03 opened this issue Dec 9, 2023 · 2 comments
Closed

bar custom color using data label nivo #2489

gowsi-03 opened this issue Dec 9, 2023 · 2 comments
Labels

Comments

@gowsi-03
Copy link

gowsi-03 commented Dec 9, 2023

Hi,

I Was just wondering if there is a way to set a color to a bar in a ResponsiveBar chart
For example:
import { type BarDatum } from '@nivo/bar'

const chartData: BarDatum[] = [
{
label: 'Jan',
value: 40,
},
{
label: 'Feb',
value: 60,
},
]

export default chartData

import { Meta, StoryObj } from '@storybook/react'
import { BarChart } from '@/components'
import chartData from './chartData'

const meta: Meta = {
title: 'BarChart',
component: BarChart,
}

export default meta
type Story = StoryObj
export const Default: Story = {
name: '[0] default',
render: (args) => (


<BarChart {...args} data={chartData} />

),
}

import { type BarDatum, ResponsiveBar } from '@nivo/bar'

export interface Props {
className?: string
classNames?: { wrapper?: string }
data: BarDatum[]
indexBy: string
enableLabel: boolean
isInteractive: boolean
}
const BarChart = ({
data,
indexBy = 'label',
enableLabel = false,
isInteractive = false,
}: Props) => {
return (


<ResponsiveBar
data={data}
keys={['value']}
indexBy={indexBy}
colors={(d) => d.data.color}
/>

)
}

export default BarChart

So i used indexBy proprty for barchart using this data label. I want color for specify label value if label=jan color shoud red if label=Feb color should green. How i customise color for my data label
Capture

Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Mar 13, 2024
@plouc
Copy link
Owner

plouc commented May 1, 2024

@gowsi-03, I'm going to close this issue for now, as it's really difficult to understand without formatting the code, please feel free to edit the issue and comment if you can provide an example and cleanup the description a bit.

@plouc plouc closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants