echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Can Bar racing Chart (realtimeSort) be sorted by the y-axis?

Open ecmap opened this issue 1 year ago • 3 comments

Version

5.5.0

Link to Minimal Reproduction

No link as the project is not opensource

Steps to Reproduce

  1. paste the code to https://echarts.apache.org/examples/en/editor.html?c=bar-race
const data = [];
const tempValue = [1, 2, 3, 4, 5]
for (let i = 0; i < 5; ++i) {
  data.push(Math.round(Math.random() * 200));
}
option = {
  xAxis: {
    max: 'dataMax'
  },
  yAxis: {
    type: 'category',
    data: tempValue,
    inverse: true,
    animationDuration: 300,
    animationDurationUpdate: 300,

  },
  series: [
    {
      realtimeSort: true,
      name: 'X',
      type: 'bar',
      data: data,
      label: {
        show: true,
        position: 'right',
        valueAnimation: true
      }
    }
  ],
  legend: {
    show: true
  },
  animationDuration: 0,
  animationDurationUpdate: 3000,
  animationEasing: 'linear',
  animationEasingUpdate: 'linear'
};
function run() {
  for (var i = 0; i < data.length; ++i) {
    if (Math.random() > 0.9) {
      data[i] += Math.round(Math.random() * 2000);
    } else {
      data[i] += Math.round(Math.random() * 200);
    }
    tempValue[i] += Math.round(0.1 + Math.random() * 2.9);
  }
  myChart.setOption({
    yAxis: {
      data: tempValue,
    },
    series: [
      {
        type: 'bar',
        data
      }
    ]
  });
}
setTimeout(function () {
  run();
}, 0);
setInterval(function () {
  run();
}, 3000);

Current Behavior

realtimeSort is based on the series data rather than yAxis.

Expected Behavior

Chart sorted by y-axis data

Environment

- OS: -
- Browser: Chrome
- Framework: -

Any additional comments?

No response

ecmap avatar May 09 '24 02:05 ecmap

I’m afraid I may not fully understand your requirement. Bar-racing charts are typically designed to sort by the value of the bars, which in your case would be the x value. If you’re interested in sorting by the y-axis, you might need to sort the data yourself before inputting it into setOption.

Ovilia avatar May 09 '24 08:05 Ovilia

I’m afraid I may not fully understand your requirement. Bar-racing charts are typically designed to sort by the value of the bars, which in your case would be the x value. If you’re interested in sorting by the y-axis, you might need to sort the data yourself before inputting it into setOption.

So, whenever realtimeSort is used, the chart will only be sorted based on the data of the series? It cannot be changed to sort based on the yAxis data?

ecmap avatar May 10 '24 03:05 ecmap

I’m afraid I may not fully understand your requirement. Bar-racing charts are typically designed to sort by the value of the bars, which in your case would be the x value. If you’re interested in sorting by the y-axis, you might need to sort the data yourself before inputting it into setOption.

So, whenever realtimeSort is used, the chart will only be sorted based on the data of the series? It cannot be changed to sort based on the yAxis data?

Yes, realtimeSort has nothing to do with that.

Ovilia avatar May 10 '24 07:05 Ovilia

I’m afraid I may not fully understand your requirement. Bar-racing charts are typically designed to sort by the value of the bars, which in your case would be the x value. If you’re interested in sorting by the y-axis, you might need to sort the data yourself before inputting it into setOption.

So, whenever realtimeSort is used, the chart will only be sorted based on the data of the series? It cannot be changed to sort based on the yAxis data?

Yes, realtimeSort has nothing to do with that.

ok

ecmap avatar May 16 '24 01:05 ecmap