Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(line): support render missing data #4185

Merged
merged 2 commits into from
Sep 30, 2022
Merged

feat(line): support render missing data #4185

merged 2 commits into from
Sep 30, 2022

Conversation

pearmini
Copy link
Member

Line 渲染缺失数据

当有不合法数据时候渲染折线图。

不链接缺失数据

image

(() => {
  const chart = new G2.Chart();

  chart
    .line()
    .data({
      type: 'fetch',
      value:
        'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
      transform: [
        // 模拟数据缺失
        {
          type: 'map',
          callback: (d) =>
            Object.assign(d, {
              close: d.date.getUTCMonth() < 3 ? NaN : d.close,
            }),
        },
      ],
    })
    .encode('x', 'date')
    .encode('y', 'close');

  return chart.render().node();
})();

连接缺失数据

image

(() => {
  const chart = new G2.Chart();

  chart
    .line()
    .data({
      type: 'fetch',
      value:
        'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
      transform: [
        // 模拟数据缺失
        {
          type: 'map',
          callback: (d) =>
            Object.assign(d, {
              close: d.date.getUTCMonth() < 3 ? NaN : d.close,
            }),
        },
      ],
    })
    .encode('x', 'date')
    .encode('y', 'close')
    .style('connectNull', true);

  return chart.render().node();
})();

设置连接缺失数据区间线段的样式

image

(() => {
  const chart = new G2.Chart();

  chart
    .line()
    .data({
      type: 'fetch',
      value:
        'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
      transform: [
        // 模拟数据缺失
        {
          type: 'map',
          callback: (d) =>
            Object.assign(d, {
              close: d.date.getUTCMonth() < 3 ? NaN : d.close,
            }),
        },
      ],
    })
    .encode('x', 'date')
    .encode('y', 'close')
    .style('missingStroke', 'red')
    .style('missingLineWidth', 10)
    .style('connectNull', true);

  return chart.render().node();
})();

src/shape/line/curve.ts Outdated Show resolved Hide resolved
@hustcc hustcc merged commit 6283354 into v5 Sep 30, 2022
@hustcc hustcc deleted the feat/line-missing-data branch September 30, 2022 09:59
hustcc pushed a commit that referenced this pull request May 16, 2023
* feat(line): support render missing data

* fix: ci
hustcc pushed a commit that referenced this pull request May 16, 2023
* feat(line): support render missing data

* fix: ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants