Last active
June 21, 2020 09:06
-
-
Save kronaemmanuel/f08bb4f343064e2917eb3fdbadd9cc2b to your computer and use it in GitHub Desktop.
Nivo Bar Chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ResponsiveBar } from '@nivo/bar' | |
// Code for Bar chart | |
const MyResponsiveBar = ({ data }) => ( | |
<ResponsiveBar | |
data={data} | |
keys={[ 'hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut' ]} | |
indexBy="country" | |
margin={{ top: 50, right: 130, bottom: 50, left: 60 }} | |
padding={0.3} | |
colors={{ scheme: 'nivo' }} | |
defs={[ | |
{ | |
id: 'dots', | |
type: 'patternDots', | |
background: 'inherit', | |
color: '#38bcb2', | |
size: 4, | |
padding: 1, | |
stagger: true | |
}, | |
{ | |
id: 'lines', | |
type: 'patternLines', | |
background: 'inherit', | |
color: '#eed312', | |
rotation: -45, | |
lineWidth: 6, | |
spacing: 10 | |
} | |
]} | |
fill={[ | |
{ | |
match: { | |
id: 'fries' | |
}, | |
id: 'dots' | |
}, | |
{ | |
match: { | |
id: 'sandwich' | |
}, | |
id: 'lines' | |
} | |
]} | |
borderColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }} | |
axisTop={null} | |
axisRight={null} | |
axisBottom={{ | |
tickSize: 5, | |
tickPadding: 5, | |
tickRotation: 0, | |
legend: 'country', | |
legendPosition: 'middle', | |
legendOffset: 32 | |
}} | |
axisLeft={{ | |
tickSize: 5, | |
tickPadding: 5, | |
tickRotation: 0, | |
legend: 'food', | |
legendPosition: 'middle', | |
legendOffset: -40 | |
}} | |
labelSkipWidth={12} | |
labelSkipHeight={12} | |
labelTextColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }} | |
legends={[ | |
{ | |
dataFrom: 'keys', | |
anchor: 'bottom-right', | |
direction: 'column', | |
justify: false, | |
translateX: 120, | |
translateY: 0, | |
itemsSpacing: 2, | |
itemWidth: 100, | |
itemHeight: 20, | |
itemDirection: 'left-to-right', | |
itemOpacity: 0.85, | |
symbolSize: 20, | |
effects: [ | |
{ | |
on: 'hover', | |
style: { | |
itemOpacity: 1 | |
} | |
} | |
] | |
} | |
]} | |
animate={true} | |
motionStiffness={90} | |
motionDamping={15} | |
/> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment