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

🐛 使用自定义总计,当行为空,列上有指标维度,开启总计后,数据展示异常 #2177

Closed
4 tasks
liran19960215 opened this issue Apr 24, 2023 · 6 comments

Comments

@liran19960215
Copy link

liran19960215 commented Apr 24, 2023

🏷 Version

Package Version
@antv/s2 1.43.0
@antv/s2-react
@antv/s2-vue 1.5.0

Sheet Type

  • [√] PivotSheet
  • TableSheet
  • GridAnalysisSheet
  • StrategySheet
  • EditableSheet

🖋 Description

使用自定义总计,当行为空,列上有指标维度,开启总计后,数据展示异常
image
行列交叉模型如图所示
image

⌨️ Code Snapshots

import { PivotSheet, EXTRA_FIELD } from '@antv/s2';

fetch('https://assets.antv.antgroup.com/s2/basic.json')
  .then((res) => res.json())
  .then((data) => {
    const container = document.getElementById('container');
    const s2DataConfig = {
      fields: {
        rows: [''],
        columns: ['type', 'province'],
        values: ['price'],
      },
      meta: [
        {
          field: 'province',
          name: '省份',
        },
        {
          field: 'city',
          name: '城市',
        },
        {
          field: 'type',
          name: '商品类别',
        },
        {
          field: 'price',
          name: '价格',
        },
      ],
      data,
    };

    const calcFunc = (query, data) => {
      const sum = data.reduce((pre, next) => {
      console.log(pre, next[next[EXTRA_FIELD]])
        return pre + Number(next[next[EXTRA_FIELD]]);
      }, 0);
      return sum;
    };

    const s2Options = {
      width: 600,
      height: 480,
      // 配置小计总计显示
      totals: {
        row: {
          showGrandTotals: true,
          showSubTotals: true,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['province'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
        col: {
          showGrandTotals: true,
          showSubTotals: false,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['type'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
      },
    };
    const s2 = new PivotSheet(container, s2DataConfig, s2Options);

    s2.render();
  });

🔗 Reproduce Link

https://s2.antv.antgroup.com/examples/analysis/totals/#custom

🤔 Steps to Reproduce

  1. 打开demo链接 https://s2.antv.antgroup.com/examples/analysis/totals/#custom
  2. 使用如下代码替换编辑器中代码
import { PivotSheet, EXTRA_FIELD } from '@antv/s2';

fetch('https://assets.antv.antgroup.com/s2/basic.json')
  .then((res) => res.json())
  .then((data) => {
    const container = document.getElementById('container');
    const s2DataConfig = {
      fields: {
        rows: [''],
        columns: ['type', 'province'],
        values: ['price'],
      },
      meta: [
        {
          field: 'province',
          name: '省份',
        },
        {
          field: 'city',
          name: '城市',
        },
        {
          field: 'type',
          name: '商品类别',
        },
        {
          field: 'price',
          name: '价格',
        },
      ],
      data,
    };

    const calcFunc = (query, data) => {
      const sum = data.reduce((pre, next) => {
      console.log(pre, next[next[EXTRA_FIELD]])
        return pre + Number(next[next[EXTRA_FIELD]]);
      }, 0);
      return sum;
    };

    const s2Options = {
      width: 600,
      height: 480,
      // 配置小计总计显示
      totals: {
        row: {
          showGrandTotals: true,
          showSubTotals: true,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['province'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
        col: {
          showGrandTotals: true,
          showSubTotals: false,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['type'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
      },
    };
    const s2 = new PivotSheet(container, s2DataConfig, s2Options);

    s2.render();
  });

😊 Expected Behavior

image
使用自定义总计后,该种交叉模型下,开启总计后,发现数据行展示异常为空,期望结果是能正常展示数据。

😅 Current Behavior

image
使用自定义总计后,该种交叉模型下,开启总计后,发现数据行展示异常为空。

💻 System information

Environment Info
System
Browser
@liran19960215
Copy link
Author

使用自定义总计,当行上有指标维度(valueInCols: false),列上为空的情况下(column: ['']),也会出现此类展示异常的问题
https://s2.antv.antgroup.com/zh/examples/analysis/totals/#basic

import { PivotSheet, EXTRA_FIELD } from '@antv/s2';

fetch('https://assets.antv.antgroup.com/s2/basic.json')
  .then((res) => res.json())
  .then((data) => {
    const container = document.getElementById('container');
    const s2DataConfig = {
      fields: {
        rows: ['type', 'province'],
        columns: [''],
        values: ['price'],
        valueInCols: false,
      },
      meta: [
        {
          field: 'province',
          name: '省份',
        },
        {
          field: 'city',
          name: '城市',
        },
        {
          field: 'type',
          name: '商品类别',
        },
        {
          field: 'price',
          name: '价格',
        },
      ],
      data,
    };

    const calcFunc = (query, data) => {
      const sum = data.reduce((pre, next) => {
      console.log(pre, next[next[EXTRA_FIELD]])
        return pre + Number(next[next[EXTRA_FIELD]]);
      }, 0);
      return sum;
    };

    const s2Options = {
      width: 600,
      height: 480,
      // 配置小计总计显示
      totals: {
        row: {
          showGrandTotals: true,
          showSubTotals: true,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['province'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
        col: {
          showGrandTotals: true,
          showSubTotals: false,
          reverseLayout: true,
          reverseSubLayout: true,
          subTotalsDimensions: ['type'],
          calcTotals: {
            calcFunc,
          },
          calcSubTotals: {
            calcFunc,
          },
        },
      },
    };
    const s2 = new PivotSheet(container, s2DataConfig, s2Options);

    s2.render();
  });

@lcx-seima
Copy link
Contributor

没有把行/列维度 field 设为 [''] 的用法。。。

@liran19960215
Copy link
Author

没有把行/列维度 field 设为 [''] 的用法。。。

那如果行/列为空 数据就无法展开了吗

@serializedowen
Copy link
Member

serializedowen commented May 15, 2023

用法暂不支持,自行尝试使用自定义单元格。

@lijinke666
Copy link
Member

[''] 不是为空, 语义代表有一个维度, 维度叫 '', 空数组才是 [] 为空, 请不要自行发明用法或者骚操作...

看上去你的诉求如果是单个行/列 不显示维值, 只显示 S2 提供的总计, 你可以自己洗一下数据, 自己创建一个 总计 的维值, 而不是用 S2 内部计算出来的

@Flourad
Copy link

Flourad commented Apr 2, 2024

[''] 不是为空, 语义代表有一个维度, 维度叫 '', 空数组才是 [] 为空, 请不要自行发明用法或者骚操作...

看上去你的诉求如果是单个行/列 不显示维值, 只显示 S2 提供的总计, 你可以自己洗一下数据, 自己创建一个 总计 的维值, 而不是用 S2 内部计算出来的

请问怎么创建一个总计维度?有没有例子可以参考的

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

No branches or pull requests

5 participants