echarts icon indicating copy to clipboard operation
echarts copied to clipboard

legend 中的图例有没有方法做到最少保留一个不被取消选中?

Open devtorich opened this issue 8 years ago • 2 comments

One-line summary [问题简述]

legend 中的图例有没有方法做到最少保留一个不被取消选中?

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:
  • Browser version [浏览器类型和版本]:
  • OS Version [操作系统类型和版本]:

bc05sz8 9ud6n5zjz82 2 l

Expected behaviour [期望结果]

保留一个不被选 中

ECharts option [ECharts配置项]

option = {
        legend: {
            type: 'scroll',
            width: '90%',
            pageIconSize: 10,
            pageIconColor: '#1890ff',
            pageIconInactiveColor: '#1890ff4d',
            pageTextStyle: {
                color: '#8c8c8c'
            },
            data: ["何布月对", "正命速会", "极内取量", "方管形低"]
        },
}

Other comments [其他信息]

devtorich avatar Jun 25 '18 10:06 devtorich

可以监听 派发 legend事件,hack一下:

mychart.on('legendselectchanged', params => {
    let selected = params.selected;
    let count = Object.keys(selected).reduce((acc, val) => {
        return acc + (selected[val] ? 1 : 0);
    }, 0);

    if (count === 0) {
        mychart.dispatchAction({
            type: 'legendSelect',
            name: params.name
        });
    }
});

jeneser avatar Jul 18 '18 07:07 jeneser

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 18 '20 05:07 stale[bot]