apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.2k stars 19.61k forks source link

点击图表某个bar或者pie某块 动态设置itemStyle的color不生效 #9636

Closed zonday closed 5 years ago

zonday commented 5 years ago

General Questions

In this issue, I have provided information with: 在这个 issue 中我提供了以下信息:

Issue Type

Issue Details

点击图表某个bar或者pie某块 动态设置itemStyle的color 不生效,多次快速点击可能会有变化

Expected Behavior

Current Behavior

Online Example

var data= [
    {value:335, name:'直接访问', id: 1, color: 'red', itemStyle: {color: 'red'}},
    {value:310, name:'邮件营销', id: 2, color: 'green', itemStyle: {color: 'green'}},
];

option = {
    legend: {
        orient: 'vertical',
        x: 'left',
        data:['直接访问','邮件营销']
    },
    series: [
        {
            name:'访问来源',
            type:'pie',
            radius: ['50%', '70%'],
            hoverAnimation: false,
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data: data,
        }
    ]
};

myChart.on('click', "series.pie", function (param) {
    option.data = data.map(d => {
        const newD = Object.assign({}, d);
        d.itemStyle = {color: d.color};
        if (d.id === param.data.id) {
            d.itemStyle.color = 'yellow';
        }
        return newD;
    });

    myChart.setOption(option);
});

4.1.0 版本是正常的

Topics

Anything Else We Need to Know

Environment

cuijian-dexter commented 5 years ago

d.itemStyle.normal.color = 'yellow';

pissang commented 5 years ago

It seems to be a bug.

100pah commented 5 years ago

Fixed and will be released in 4.2.0-rc.3.

likwotsing commented 5 years ago

Oh, find it half day, It's here. It has been tested and fixed, thank you!