labelFormat or labelBy to access (value, id, data) similar to colorBy
See original GitHub issueIn a bar chart, I can colour the bars using my own calculation with colorBy
. Works great (need in heatmap!)
But I constantly find I need the same power with labels https://github.com/plouc/nivo/issues/64 https://github.com/plouc/nivo/issues/146
Currently all we can access is the value:
labelFormat: value => Math.round(value)
<-- I can make 5.234235 show as 5
labelFormat: value => moment.duration(value).format('HH:mm:ss', { trim: false })
<-- 10000 becomes 00:00:10
But I cannot do this (where value=150):
labelFormat: (value, id, data) => data[id+'Color'] === 'red' ? value : ''
// hidden if red
labelFormat: (value, id, data) => data[id+'MyStep'] + value
// Step 2A: 150
labelFormat: (value, id, data) => data[id+'AltValue']
// a label unrelated to value for calculating bar
@plouc Could a labelBy
method be added to handle this (and other labels such as tooltip, axis…)
I tried to change the source code but so far have not succeeded.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:11 (2 by maintainers)
Top GitHub Comments
Here is my implementation of total value label on top of nivo’s stacked bars:
https://codesandbox.io/s/nivo-basic-demo-t1z56?file=/src/index.js
Any progress on this? I have a pretty good use case where I have a stacked bar graph that shows the number of total “sessions” created, but some are of one type and some are another. I’d like to show the # of each type, but also show the combined total at the top of each stacked bar! This feature would allow us to do that