Unable to change color of axis legends in ResponsiveBar
See original GitHub issueI have a responsive bar chart that I’m unable to change the color of the axisLeft and axisBottom Legend text, it seems to always be black.
- I have tried the
theme
property from issue#132 and was able to change some colors to better fit my theme, but not the axis legend text colors. - I also tried the solution of issue#257 to add
textColor
into the legends array, and was able to change the text to white in the legend usingitemTextColor
but did not affect the axis label text. - I also tried the
theme
settings in the sandbox example on issue#311 which is great for setting the actual grid, but did not change the axis labels from black. - I attempted to look through the code to see if I could find where that axis label is generated and inherits the color from, but there is a lot of code to go through and was unable to track it down.
- Lastly, I tried just brute forcing some properties as a last resort to see if I could get lucky with finding the correct setting, which is why I’m now posting here.
Code:
import React from 'react';
import { ResponsiveBar } from '@nivo/bar';
const data = [
{
"map": "RoL",
"wins": 120,
"loss": 193,
},
{
"map": "DS",
"wins": 35,
"loss": 160,
},
{
"map": "TA",
"wins": 33,
"loss": 120,
},
{
"map": "TTP",
"wins": 27,
"loss": 3,
},
{
"map": "BRH",
"wins": 199,
"loss": 19,
},
{
"map": "NA",
"wins": 117,
"loss": 107,
},
{
"map": "AF",
"wins": 195,
"loss": 156,
},
{
"map": "BEA",
"wins": 195,
"loss": 156,
},
{
"map": "HP",
"wins": 195,
"loss": 156,
},
{
"map": "M",
"wins": 195,
"loss": 156,
}
]
const Bar = () => (
<ResponsiveBar
data={data}
keys={[
"wins",
"loss",
]}
indexBy="map"
margin={{
"top": 50,
"right": 130,
"bottom": 50,
"left": 60
}}
padding={0.3}
colors="dark2"
colorBy="id"
borderColor="inherit:darker(1.6)"
axisTop={null}
axisRight={null}
axisBottom={{
"tickSize": 5,
"tickPadding": 5,
"tickRotation": 0,
"legend": "Map",
"legendPosition": "middle",
"legendOffset": 32,
}}
axisLeft={{
"tickSize": 5,
"tickPadding": 5,
"tickRotation": 0,
"legend": "Wins / Loss",
"legendPosition": "middle",
"legendOffset": -40,
}}
labelSkipWidth={12}
labelSkipHeight={12}
labelTextColor="#ffffff"
animate={true}
motionStiffness={90}
motionDamping={15}
theme={{
axis: {
fontSize: '14px',
tickColor: '#eee',
ticks: {
line: {
stroke: "gray"
},
text: {
fill: "#ffffff",
},
},
},
}}
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,
"itemTextColor": '#ffffff',
"symbolSize": 20,
"effects": [
{
"on": "hover",
"style": {
"itemOpacity": 1
}
}
]
}
]}
/>
)
export default Bar
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Solved: Cant change the colour on bars when i use axis, Le...
Solved: Hello, Cant change the colour on bars(Clustered column chart) when i use axis, Legend and values at the same time Source data...
Read more >@nivo/bar axis legend text color #443 - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >Changing the colors of the horizontal axis labels in a bar graph
I have created a gantt chart in Excel and I am trying to change the colors of my tasks that are the horizontal...
Read more >Bar chart | nivo
Bar chart which can display multiple data series, stacked or side by side. Also supports both vertical and horizontal layout, with negative values ......
Read more >Colors from data not being displayed in Nivo ResponsiveBar
You can set the colors props with a function mapping to your color field : <ResponsiveBar ...... colors={({id, data}) => data[`${id}Color`]} ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@PaulLNH, you can use
axis.legend.text.fill
, I’ve created an example => https://codesandbox.io/s/000mv35lxnHey is this still available for the latest version? This does not seem to work for this. ( v0.59.0 ).
Thanks!