Customize legend labels in Stream component
See original GitHub issueHello, I’ve read the docs for Stream and Legend but did not find anything regarding how to customize legend labels.
I’ve a situation like this:
const data = [
{
JD: 10500,
PC: 6700,
date: '2018-09'
},
{
JD: 7860,
PC: 5430,
date: '2018-08'
}
];
const sellers = [
{
id: 'JD',
name: 'John Dorian'
},
{
id: 'PC',
name: 'Percival Cox'
}
];
const keys = sellers.map(s => s.id);
There is a way to display the name
of each seller inside the legend instead of their id apart from mapping the data array and change it to use seller’s name as keys instead of their id?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:14 (1 by maintainers)
Top Results From Across the Web
GGPlot Legend Title, Position and Labels - Datanovia
This R graphics tutorial shows how to customize a ggplot legend. ... Rename legend labels and change the order of items in a...
Read more >How to Customize Legend With GenerateLabels in Chart JS
How to Customize Legend With GenerateLabels in Chart JSIn this video we will explore how to customize legend with generatelabels in chart js ......
Read more >Work with a legend item—ArcGIS Pro | Documentation
If a legend item does not include labels, the count appears adjacent to the patch. Use the text boxes to customize the text...
Read more >Solved: Custom name legend - Microsoft Power BI Community
Custom name legend · Click your chart, and click the small triange next to the measure name on fields tab. · Click the...
Read more >Legend in React Chart component - Syncfusion
You can also customize the fontStyle , size , fontWeight , color , textAlignment , fontFamily , opacity and textOverflow of legend title....
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
I decided to use keys for legends for the sake of simplicity, I don’t see why it’s ridiculous as it’s totally fine to have a key named
'With Something'
. And if your data storage doesn’t allow to use such keys, you can easily map the data prior to passing it to the chart:useMemo
is optional, but it should be used to prevent unnecessary renderings.That being said, I admit it could be nice to override the labels/legends… but using a simple mapping can be limiting, for example you won’t be able to compute those depending on the values, maybe the lib could support a
get(Label|Legend)
property which receive the whole datum.@plouc I think a pattern like
get(label|legend)
is necessary.For instance, I have am using a very large dataset with two letter states for keys like so:
const keys = ['nv', 'al', 'az',]
Now if I want my labels to show as “Nevada, Alabama, Arizona” it’s not as simple as just mapping over my keys that I pass into the
keys
prop ofBarChart
. I would now have to change the keys of my whole dataset indata
so that they matchkeys
. This is untenable for very large datasets and seems like a really bad pattern to be manipulating my actual dataset for something that is purely presentational.