Skip to content

“Bar chart – Overlay Mode” unexpected behavior.  #1973

Closed
@nyan314sn

Description

@nyan314sn

This post is related to #475

Positive and negative values can be stacked on each side of the zero line.
The problem can be replicated using codepen https://codepen.io/etpinard/pen/mPGLrY with the following code.
`console.log(Plotly.version)

    var trace1 = {
      x: ['giraffes', 'orangutans', 'monkeys','dogs'],
      y: [1, 3, -5,-2],
      name: 'SF Zoo',
      type: 'bar'
    };
    var trace2 = {
      x: ['giraffes', 'orangutans', 'monkeys','dogs'],
      y: [2, 2, 4,4],
      name: 'LA Zoo',
      type: 'bar'
    };
    var trace3 = {
      x: ['giraffes', 'orangutans', 'monkeys','dogs'],
      y: [3,1, -2,-5],
      name: 'LA Zoo',
      type: 'bar'
    };
    var data = [trace1, trace2,trace3];
    var layout = { 
      title: 'click on modebar buttons to change \'barmode\''
    };

    var config = {
      modeBarButtons: [[{
        name: 'stack',
        click: function(gd) {
          Plotly.relayout(gd, 'barmode', 'stack');
        }
      }, {
        name: 'overlay',
        click: function(gd) {
          Plotly.relayout(gd, 'barmode', 'overlay');
        }
      }, {
        name: 'group',
        click: function(gd) {
          Plotly.relayout(gd, 'barmode', 'group');
        }, 
      }, {
        name: 'relative',
        click: function(gd) {
          Plotly.relayout(gd, 'barmode', 'relative');
        }, 
      }].reverse()]
    }

    Plotly.newPlot('graph', data, layout, config);`

The output will be like this. ( You might need to click on the image to see it better. )
over_lay_mode

“Giraffes” and “orangutans” have the very similar data (1,2,3) and (3,2,1). But, the output is different depending on the order of the input. In Giraffes, trace1 and trace 2 data are never shown up and overfilled. This shouldn’t be the desired output.
What I think it should happen is that for positive values, the bars are plotted in descending order, from largest to smallest. For negative values, the bars need to be plotted in ascending order, from smallest to largest.
Please let me know if there is an easy way to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions