antvis/G2

geom.style 的 callback 只触发一次 #3379

myou posted onGitHub

  • I have searched the issues of this repository and believe that this is not a duplicate.

https://g2.antv.vision/en/examples/line/basic#curved

Steps to reproduce

把 example code 的

chart
  .line()
  .position('month*temperature')
  .color('city')
  .shape('smooth');

改成

chart
  .line()
  .position('month*temperature')
  .style('city', (city) => {
    console.log('city', city);
    return {
      stroke: city === 'London' ? 'red' : 'blue'
    };
  })
  .shape('smooth');

会发现整个线都是蓝色,而且 city 只打印了一次。data 第一个元素 style 是用 .style callback 决定的,之后每一个元素都是用了第一个元素的 style

Environment Info
g2 4.1.14
System -
Browser -

按照 https://g2.antv.vision/en/docs/api/general/style 这里文档,style 应该是每一个数据数组元素都重新判断一次

<!-- generated by antv-issue-helper. DO NOT REMOVE -->


因为你的数据,是带有 city 粒度的,但是在绘制的时候,没有通过 color 字段将 city 分组,导致问题。

image

posted by hustcc over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests