echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Feature] 多层级轴标签

Open yzhang921 opened this issue 1 year ago • 1 comments

What problem does this feature solve?

能否实现多层级轴标签,现在的轴标签只能有一个层级,如果轴标签本身包含多层信息分类非常不明显 image

What does the proposed API look like?

期待能实现Tableau轴的层级方案 image

yzhang921 avatar Aug 26 '24 03:08 yzhang921

see #18923, there are solutions

helgasoft avatar Aug 27 '24 03:08 helgasoft

我用多 axis 魔改了一个 demo

重复的 Label 使用 customValues 来仅绘制中间的 Label.(如果是偶数重复,就选中间两者里靠后的) 偶数重复的 Label 还有一步,需要在绘制完成后拿到两个 tick 间的长度,再偏移 Label 来居中. 通过 rich 来格式化文本和插入空白的偏移占位块: {txt|XXX}{offset|} 获取两个 tick 间的长度

((axis = 'yAxis') => {
    const chart = echarts.getInstanceByDom(document.querySelector('[_echarts_instance_]'));
    const indexName = axis === 'yAxis' ? 'yAxisIndex' : 'xAxisIndex';
    // 通过 convertToPixel 来转换坐标
    const pos1 = chart.convertToPixel({[indexName]: 0}, 0);  // 转换第一个位置
    const pos2 = chart.convertToPixel({[indexName]: 0}, 1);  // 转换第二个位置
    return Math.abs(pos2 - pos1); 
})()

Justin-ZS avatar Jan 23 '25 10:01 Justin-ZS

@Justin-ZS 你这个效果看起来貌似不错,希望官方能够通过,一个轴元素实现,axis.data = [[]],可以是多维数组,否则增加轴在grid多图的场景下使用起来就复杂了

yzhang921 avatar Feb 08 '25 07:02 yzhang921