Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Expand only x axis when we drag plotly area graph

I want to expand only x axis when I drag plotly area graph. I don’t want to expand y axis. When I’m dragging area graph that time both x and y axis are expanding. I referred this code

My code is:

 <script>
var trace1 = {
x: ['2013-10-04 22:23:00', '2016-10-06 22:23:00',  '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
y: [1, 3, 6,9, 4, 5],
  fill: 'tozeroy',
  fillcolor: 'red',
  text: server1,
  hoverinfo: "x+y+text",
  name:"Server 1",
  type: 'scatter',
  mode:"markers",
  marker:
  {
	size:5,
	color:"gray"
  },
  uid:"c2e171"
};
var layout = {
  margin: {
	l: 20,
	r: 40,
	b: 40,
	t: 10
  },
  legend: {
	"orientation": "h"
  },
};
var data = [trace1];
Plotly.newPlot('myDiv', data,layout);

var plotDiv = document.getElementById('myDiv');
plotDiv.on('plotly_relayout',
function(eventdata){  
    alert( 'ZOOM!' + '\n\n' +
        'Event data:' + '\n' + 
         JSON.stringify(eventdata) + '\n\n' +
        'x-axis start:' + new Date(eventdata['xaxis.range[0]'])+ '\n' +
        'x-axis end:' + new Date(eventdata['xaxis.range[1]']));
		var xVal = new Date(eventdata['xaxis.range[0]']);
		var yVal = new Date(eventdata['xaxis.range[1]']);
});

I got solution for above problem. I need to add yaxis : {fixedrange: true} in layout.

1 Like