echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Cannot stack bars on time x-axis

Open ghost opened this issue 7 years ago • 27 comments

One-line summary [问题简述]

Stacked bar charts collapsed since 4.0.3. See screenshot.

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 4.0.4
  • Browser version [浏览器类型和版本]: Chrome 64
  • OS Version [操作系统类型和版本]: macOS High Sierra

Expected behaviour [期望结果]

Bars able to stack on top of each other without overflowing issues.

ECharts option [ECharts配置项]

option = { 
  grid: {
    right: '8%',
    left: '8%'
  },
  xAxis: {
      type: 'time',
      minInterval: 1000 * 3600 * 24
  },
  yAxis: {
    type: 'value',
    min: 0,
    max: 100,
    name: '%'
  },
  series: [
  {
    type: 'bar',
    stack: 'adherence',
   data: [{
       value: ['2018-02-21', 6, 2, 33, 67]
     }],
    encode: { x: 0, y: 3 },
    barMaxWidth: 25,
    barCategoryGap: '50%',
    cursor: 'auto',
    itemStyle: {
      normal: {
        color: 'red',
        opacity: 0.5
      }
    }
  },
  {
    type: 'bar',
    stack: 'adherence',
    data: [{
       value: ['2018-02-21', 6, 2, 33, 67]
     }],
    encode: { x: 0, y: 4 },
    barMaxWidth: 25,
    barCategoryGap: '50%',
    cursor: 'auto',
    itemStyle: {
      normal: {
        color: 'green',
        opacity: 0.5
      }
    }
  }],
  dataZoom: {
    type: 'slider',
    showDataShadow: false
  }
}

Other comments [其他信息]

screen shot 2018-03-14 at 14 44 01

ghost avatar Mar 14 '18 14:03 ghost

Switching x-axis type to 'category' solved the problem. But unsure why issue only arose after version upgrade from 4.0.2 to 4.0.4.

ghost avatar Mar 14 '18 18:03 ghost

Reopened because I need to use time for x-axis 😞

ghost avatar Mar 16 '18 14:03 ghost

I have the same problem, stacked bar chart with time x-axis worked in 4.0.2 but not until 4.0.3.

saramorillon avatar Mar 20 '18 13:03 saramorillon

Currently, stack is only supported on 'category' axis.

In fact, we've been considering whether support stack on 'time' or event 'value' axis, since it is a bit complicated than supporting it on 'category' axis.

@ClaraMedopad Could I have the detailed reason that why the 'time' axis is necessary in your case?

100pah avatar Mar 24 '18 19:03 100pah

In my case I use it to visualise medication adherence, i.e. how many tablets a patient has taken out of the total per day. I want to have an overview of the continuous data, i.e. if the medication is stopped or not required for the day, a gap will be shown in the bar chart.

screen shot 2018-03-26 at 10 06 41

Example in the above screenshot, 2017-08-05 and 2017-08-07 does not show because no medication is prescribed, but it will be helpful to visualise that to the doctor.

A bar chart is used in this case to visualise the percentage completion of the daily dosage. I cannot think of alternative ways to display it other than stacked bar on time axis so any advice is welcomed.

ghost avatar Mar 26 '18 08:03 ghost

Same issue here, I use echarts to visualize memory consumption over time and I stack the memory usages to display the repartition of the overall memory usage. eg: heap memory + off-heap memory = total memory consumed, thus I want to stack series as in the following plot: image

BenoitHanotte avatar Mar 29 '18 13:03 BenoitHanotte

Same issue, I need to stack registrations of different types at different dates, and categories doesn't work since some days are empty and should still appear.

Xalio08 avatar Feb 26 '19 13:02 Xalio08

our use-case is almost like the Confidence Band example, but:

  • but for the line-series, we need the time axis
  • for the confidence band we could use a category axis

any ideas for a workaround? e.g.

  1. maybe we can have 2 x-axis: a time-axis for the line-series and a category axis for the (confidence band stack)? But those axis would need to be "sychronized": e.g. when we zoom in, both must zoom together, etc.
  2. or is it worth to try to keep only one time-axis and use a custom series to draw the area? If so, can someone link to an example, how to use custom-series with a time x-axis?
    The answer is NO. Custom series are just too slow (much slower than native series). Drawing the graphics basically works, but when we have like 10 charts with 5 series and 1k samples, the app is basically unusable.
  3. something completely different, that I didn't think of..

tmtron avatar Mar 17 '19 08:03 tmtron

In fact, we've been considering whether support stack on 'time' or event 'value' axis, since it is a bit complicated than supporting it on 'category' axis.

@100pah: will it be simpler to support only a special case and not the general case to stack 2 different series (which may have data-samples at different time-stamps)?

e.g. when you have measurement data, you often need to display the min and max values of a series (instead of just e.g. the average) to avoid aliasing: e.g. in the screenshot below we have one such series (1) is the maximum and (2) is the minimum: so each of the samples have a time-stamp and they always have min and max: image

tmtron avatar Jul 01 '19 20:07 tmtron

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 Sep 03 '21 21:09 github-actions[bot]

+1 don't close

tmtron avatar Sep 04 '21 08:09 tmtron

+1, we need stacking with x-axis type value

alexciesielski avatar Sep 13 '21 08:09 alexciesielski

+1, I assume same solution to #15102

hughess avatar Nov 03 '21 14:11 hughess

+1, It's related to #16177 and #16099

We also need stacking bars on time xAxis like the example provided in #16177.

th1under avatar Dec 07 '21 05:12 th1under

+1 Still broken, we're interested to use stacked bar with time.

ghost avatar Sep 16 '22 13:09 ghost

Has something changed that makes this slightly more supported now or are there still limitations on stacking on a time axis? When I try the options provided by the original poster, it looks like it might be properly stacked now.

image

juliepagano avatar Oct 20 '23 17:10 juliepagano

It seems this still does not work for time, value, and log. :-(

mitar avatar Jan 10 '24 16:01 mitar

@mitar, stacked bars on time axis work - Demo code

helgasoft avatar Jan 11 '24 06:01 helgasoft

@helgasoft So this issue can be then closed?

mitar avatar Jan 11 '24 08:01 mitar

@mitar, stacked bars on time axis work - Demo code

It works with your specific data which has all values for all series. I changed a single character (the last datapoint) and here's the incorrect result.

gggdomi avatar May 28 '24 08:05 gggdomi

It works with your specific data which has all values for all series.

yes @gggdomi. And "incorrect results" are due to missing values which could/should be fixed by data preprocessing. Demo with missing values added.

FAQ: ECharts axis types

ECharts has four axis types available - value, category, time and log.

  • category is a discrete axis with individual values
  • time and value are continuous axes with a range of values without gaps
  • log is a non-linear axis dealing with very-large-range values

Character data are naturally discrete and can only be represented on a category axis. Examples: ['Peru','Cuba','Japon',...] or ['Mon','Tue','Wed',...] or ['TypeA','TypeB',...]. Numerical data is usually continuous, like temperature, price or distance. Time data is also continuous, with resolution in minutes, days or years.

All axis types allow for missing data, but present them differently. For instance A bar chart with data:[['Feb',22], ['Oct',44]] on a category axis will present them side-by-side, but data:[['2024-02',22], ['2024-10',44]] on a time axis will show continuous time without data in-between. Missing time data, as null or interpolated values, could be added in a data pre-processing step. Data transformation is a developer's task. Often data has to be modified to meet the needs of a chosen charting library and not the other way around.

Log axis is not suitable for stacked charts. A stacked chart relies on a linear axis to show proportions, but log axis is not linear.


helgasoft avatar May 28 '24 21:05 helgasoft