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

[Bug] Bar chart with legend issue #19581

Open
luojiandan opened this issue Jan 31, 2024 · 1 comment
Open

[Bug] Bar chart with legend issue #19581

luojiandan opened this issue Jan 31, 2024 · 1 comment
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.

Comments

@luojiandan
Copy link

luojiandan commented Jan 31, 2024

Version

5.4.3

Legend shows color of different series.
But my chart has only one series,data color by different sport.
I want to show Legend by colors Variables.

Code:

`
//test data
var arrDatas = [
{
name: 'Ronaldo',
sport: 'Football',
salary: 1.36
},
{
name: 'Messi',
sport: 'Football',
salary: 1.3
},
{
name: 'Mbappe',
sport: 'Football',
salary: 1.2
},
{
name: 'James',
sport: 'Basketball',
salary: 1.19
},
{
name: 'Alvarez',
sport: 'Boxing',
salary: 1.1
},
{
name: 'Johnson',
sport: 'Golf',
salary: 1.07
},
{
name: 'Federer',
sport: 'Tennis',
salary: 0.95
}
];
//color data
var colors = {
Basketball: '#D09726',
Football: '#27D0B3',
Tennis: '#267FCF',
Golf: '#4CF53E',
Boxing: '#D02F27'
};
option = {
xAxis: {
type: 'category',
axisLabel:{
interval:0, //show all
},
data: arrDatas.map((item) => item.name +'('+ item.sport+')')
},
yAxis: {
type: 'value'
},
legend: {},
series: [
{
name:'sport',
type: 'bar',
data: arrDatas.map((item) => ({
value: item.salary,
itemStyle: {
color: colors[item.sport] //color
}
}))
}
]
};

`

Current Behavior

1.create bar chart like this:
Example Code

2.the default legend is not right
It only show one color:
image

but not show color by sport name.
`
//color data
var colors = {
Basketball: '#D09726',
Football: '#27D0B3',
Tennis: '#267FCF',
Golf: '#4CF53E',
Boxing: '#D02F27'
};

`

No response

@luojiandan luojiandan added the bug label Jan 31, 2024
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Jan 31, 2024
@MatthiasMert
Copy link

MatthiasMert commented Jan 31, 2024

If legend data is not supplied it is populated with series names. So put one series per sport name and it will show up correctly.

Demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.
Projects
None yet
Development

No branches or pull requests

2 participants