echarts Bar stacking doesn't work if the x-axis is value type instead of category type

44u64gxh  于 2022-11-02  发布在  Echarts
关注(0)|答案(4)|浏览(219)

Version

5.1.1

Steps to reproduce

Use the following in the editor

option = {
    xAxis: {
        type: 'value',
        data: [1,2,3,4,5,6,7]
    },
    yAxis: {
        type: 'value'
    },
    "legend": {
        "show": true,
        "type": "scroll",
        "padding": 5,
        "selector": [
            "all",
            "inverse"
        ],
        "top": 5
    },
    series: [{
        name: "a",
        data: [120, 200, 150, 80, 70, 110, 130],
        type: 'bar',
        stack: 'one'
    }, {
        name: "b",
        data: [120, 200, 150, 80, 70, 110, 130],
        type: 'bar',
        stack: 'one'
    }]
};

What is expected?

I expected to see a stacked bar chart.

What is actually happening?

It shows only one of the two series.

Just change the type from 'value' to 'category' for xAxis and everything is good.

n8ghc7c1

n8ghc7c11#

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it containsa minimum reproducible demoand necessaryimagesto illustrate. Otherwise, our committers will ask you to do so.

  • A minimum reproducible demo* should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org . Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list .

Have a nice day! 🍵

qpgpyjmq

qpgpyjmq2#

This is very lightly mentioned in the series-bar documentation, but should definitely be more prominent.

sqyvllje

sqyvllje3#

Some fields like grade of the student are numeric. What I see with bar charts is that they work great with category axis type and the data being string. If it is value type and/or numeric data then there are challenges. Any reason for limiting the full bar chart capabilities for value type and numeric data?

li9yvcax

li9yvcax4#

+1 for needing stacking on a value axis.

Biggest problem for me with this is missing values - there may be parts of your x-axis where none of your series have any observations. It's a pain to have to iterate through the dataset and prepare it so that it shows missing data.

For example:

series1 = [
   [3, 10],
   [4, 13],
   [5, 16],
   [8, 21]
]

series2 = [
   [3, 15],
   [4, 17],
   [5, 21],
   [8, 23]
]

Using a category axis with this data won't show 6 or 7 on the axis. Using value would work if stacking was possible.

The current workaround for this would be to iterate through each of these series, see which x values are missing, and recreate the data so that 6 and 7 are included as rows in each dataset.

One approach that might work is to treat this situation in the same way as a histogram:

  • Assume a default interval based on the data provided to the chart (e.g., if it's years or integers, interval = 1. If it's a continuous variable, have some default logic to assume an interval)
  • Bin the data using the interval
  • Plot the data, effectively treating the x-axis as a category axis
  • You could probably even explicitly treat the axis as category - at least for me, I don't care if the axis is value or category. I would just prefer not to have to write the code to check/fill values for each chart I build

相关问题