G2 icon indicating copy to clipboard operation
G2 copied to clipboard

[Bug]: legend 配置 maxCols 未生效

Open ixuxinyue opened this issue 6 months ago • 5 comments

Describe the bug / 问题描述

import { Chart } from '@antv/g2';

const chart = new Chart({ container: 'container', height: 350 });
const shapeList = ['bowtie', 'smooth', 'hv', 'rect', 'hollowPoint'];
const data = [
  { genre: 'Sports', sold: 50 },
  { genre: 'Strategy', sold: 115 },
  { genre: 'Action', sold: 120 },
  { genre: 'Shooter', sold: 350 },
  { genre: 'Other', sold: 150 },
];
chart.options({
  type: 'interval',
  data,
  encode: { x: 'genre', y: 'sold', color: 'genre' },
  legend: {
    color: {
      maxCols: 1
    },
  },
});

chart.render();

Reproduction link / 复现链接

(https://g2.antv.antgroup.com/manual/component/legend#%E9%85%8D%E7%BD%AE%E9%A1%B9)

Steps to Reproduce the Bug or Issue / 重现步骤

Image

Version / 版本

Please select / 请选择

OS / 操作系统

  • [x] macOS
  • [ ] Windows
  • [ ] Linux
  • [ ] Others / 其他

Browser / 浏览器

  • [x] Chrome
  • [ ] Edge
  • [ ] Firefox
  • [ ] Safari (Limited support / 有限支持)
  • [ ] IE (Nonsupport / 不支持)
  • [ ] Others / 其他

ixuxinyue avatar Jul 02 '25 07:07 ixuxinyue

图例水平的时候只有maxRows生效,之前是这么设计的

interstellarmt avatar Jul 10 '25 04:07 interstellarmt

图例水平的时候只有maxRows生效,之前是这么设计的

那在图例水平的时候,如何实现maxCols 的效果呢,即最大列数为3,但是随着宽度减小会自适应减少legend列数 现在是不是没有办法做到

ixuxinyue avatar Jul 17 '25 12:07 ixuxinyue

配置一下 length试试呢 https://g2.antv.antgroup.com/manual/faq#%E6%80%8E%E4%B9%88%E8%B0%83%E6%95%B4%E5%9B%BE%E4%BE%8B%E7%BB%84%E4%BB%B6%E6%95%B4%E4%BD%93%E7%9A%84%E5%A4%A7%E5%B0%8F%E5%92%8C%E5%B8%83%E5%B1%80

interstellarmt avatar Jul 17 '25 12:07 interstellarmt

配置一下 length试试呢 https://g2.antv.antgroup.com/manual/faq#%E6%80%8E%E4%B9%88%E8%B0%83%E6%95%B4%E5%9B%BE%E4%BE%8B%E7%BB%84%E4%BB%B6%E6%95%B4%E4%BD%93%E7%9A%84%E5%A4%A7%E5%B0%8F%E5%92%8C%E5%B8%83%E5%B1%80

length配了之后,legend的宽度就固定了,达不到我想要的自适应效果叻 - 即图表被拉宽但是最大legend列为 maxCols (假如 为 4),图表被缩扁,legend列数从 4,变为3,变为 2..

ixuxinyue avatar Jul 17 '25 13:07 ixuxinyue

@moayuisuda

lxfu1 avatar Sep 16 '25 03:09 lxfu1