Bug in bar chart? barmode relative not working in 1.5

I am using the following code

const t1 = {
  x: [1,2,3,4,5],
  y: [2,3,-3,4,-2],
  name:'Positive',
  showlegend: true,
  type: 'bar',
			
}

const t2 = {
  x: [1,2,3,4,5],
  y: [-2,-4,4,-6,3],
  name:'Negative',
  showlegend: true,
  type: 'bar',

}
    
const data = [t1, t2,];
const layout = {
  xaxis: {title: 'X axis'},
  yaxis: {title: 'Y axis'},
  barmode: 'relative',
  title: 'Relative Barmode'
};
Plotly.newPlot('myDiv', data, layout);

This is pretty much lifted from the official docs except data.

The exact same code run with plotly.js 1.5 on my machine looks like follows
barplot

My aim is obviously to get the output in the codepen above.
This is similar to barmode group I think rather than relative.

Is this a bug or am I missing something?

Thanks

barmode: 'relative was added in v1.11.0, so when in fact that graph which uses v1.5.0 has the default barmode: 'group'.

Okay. Twice in two days you have saved me at least a few days of trouble. Thanks!
I did follow https://libraries.io/npm/plotly.js/1.11.0 and did this…
npm install plotly.js@1.11.0

It worked. And I have never been able to install plotly through npm, before. Without specifying version that is.
Now it just works…with real data this time…
barplot1

Before I celebrate too much, please, is this the right version to use right now? Or have we moved on to a more recent one?
It seems google is not doing justice to you guys. The best I could come up with is in the thread.
This npm version could have saved me a week at least. I hope this thread makes a difference to someone else.

Can’t thank you enough.
Cheers and peace

You can download https://cdn.plot.ly/plotly-latest.min.js whenever we make a new release.

I suggest following https://twitter.com/plotly_js to stay up-to-date.

1 Like