echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Bug] 柱状图在横轴为时间时,无法按照时间正常堆叠

Open Sorakado-Aoo opened this issue 3 years ago • 3 comments

Version

5.3.1

Link to Minimal Reproduction

No response

Steps to Reproduce

在5.2.2中正常,5.3.0之后异常 示例option

option = {
  title: { left: 'center' },
  color: [
    '#F73809',
    '#0909F7',
    '#09F7F7'
  ],
  toolbox: { right: 30, feature: { saveAsImage: {} } },
  tooltip: { trigger: 'axis' },
  legend: {
    show: true,
    padding: [10, 50],
    data: [
      'bar1',
      'bar2',
      'bar3'
    ]
  },
  grid: { left: '6%', right: '6%', bottom: '12%', containLabel: true, top: 40 },
  xAxis: {
    type: 'time',
    minInterval: 86400000,
    splitLine: { show: false },
    axisLabel: { rotate: 0 }
  },
  yAxis: {
    scale: true,
    type: 'value',
    axisLabel: { formatter: '{value} kWh' },
    min: 0,
    max: null
  },
  series: [
    {
      name: 'bar1',
      type: 'bar',
      stack: 'one',
      data: [
        ['2020/03/09', 2.498],
        ['2020/03/10', 0.501]
      ]
    },
    {
      name: 'bar2',
      type: 'bar',
      stack: 'one',
      data: [['2020/03/10', 0.827]]
    },
    {
      name: 'bar3',
      type: 'bar',
      stack: 'one',
      data: [['2020/03/10', 0.814]]
    }
  ]
};

Current Behavior

image

Expected Behavior

image

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response

Sorakado-Aoo avatar Mar 18 '22 06:03 Sorakado-Aoo

@Sorakado-Aoo It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗

TRANSLATED

TITLE

[Bug] When the horizontal axis is time, the histogram cannot be properly stacked according to time

echarts-bot[bot] avatar Mar 18 '22 06:03 echarts-bot[bot]

Problem locating

In one sentence, Echarts is stacking value by index, not by name. Both 5.2.x and 5.3.x deal with stack data here and put it in storage: https://github.com/apache/echarts/blob/3961cefc0329cfa8782602fc2aea46cc76c3f50e/src/processor/dataStack.ts#L123-L139 However, stackedDataRawIndex is only decided by index of data. So if you have a hole in your stacked data, it will cause wrong stack.

Why it works in 5.2.x

The reason why no error occurs in 5.2.x is that it's using a completely new variable to store stack info instead of taking from storage. Check the variable lastStackCoords here: https://github.com/apache/echarts/blob/000ee7d2d1272cee96b0bd19bff9207301096c8d/src/layout/barGrid.ts#L445 This is no longer the case in 5.3.x.

Why it doesn't work in 5.3.x

Echarts now pick up stack data directly from storage and the 'stack-by-index' error is unveiled as long as there's a hole in stack data. Take a look at the new function in 5.3.x. https://github.com/apache/echarts/blob/3961cefc0329cfa8782602fc2aea46cc76c3f50e/src/layout/barGrid.ts#L465

So the 'stack-by-index' problem exists in BOTH version but the way to handle it changes in 5.3.x so the error pops up.

Update (5/19/2022)

It seems that the 'stack-by-index' is intentional for time axis. Check the code here: https://github.com/apache/echarts/blob/6c793aad38450469b43007a32e2c6c05047e68da/src/data/helper/dataStackHelper.ts#L120-L124 Value/Time axis data are all set to be using index to stack so it requires user to arrange data carefully. That means no 'holes' in data. This is designed for 'value'/'time' type axes so it's not a bug. Again, USERS ARE REQUIRED TO PROVIDE ELABORATE DATA FOR TIME AXIS STACK!

jiawulin001 avatar Apr 27 '22 08:04 jiawulin001

This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.

github-actions[bot] avatar May 18 '24 21:05 github-actions[bot]

This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!

github-actions[bot] avatar May 26 '24 21:05 github-actions[bot]