✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Fixing x-axis range not working

I want to fix the x-axis range so that when you clear a trace in the legend, the x-axis range doesn’t change—even if one trace has a different range.

I tried:

range: ["2016-05-01", "2016-05-05"]

Seems this should be all it takes, but the x-axis range still changes.

If I set autorange: false in the layout object, the plot fails. The x-axis values and ticks are all messed up. Why is this?

However, if I set the autorange property after the layout object definition with

layout_autorange_after = false;

Then all goes well.

Here’s how: http://codepen.io/etpinard/pen/YGLOZm

Explanation: at the moment the xaxis.range items have to be input in computed coordinates (i.e. not user coordinates unfortunately). So, in order to set the range of a date axis, one must input xaxis.range in unix timestamps. Luckily, this can easily be done using plain JS new Date() and .getTime().

1 Like

Same behavior. Or maybe I’m not understanding what you are saying (definitely possible).

Aha!!! I added .getTime and it works. Just as you said :wink:

function getTimestamp(datestring)
{
  return (new Date(datestring)).getTime();
}

And added .map(getTimestamp) to all date lists.