# Fixing x-axis range not working

**URL:** <https://community.plotly.com/t/fixing-x-axis-range-not-working/2347>\
**Category:** plotly.js\
**Created:** [October 9, 2016, 6:16am UTC](https://community.plotly.com/t/fixing-x-axis-range-not-working/2347 "2016-10-09T06:16:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abalter](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@abalter](https://community.plotly.com/u/abalter)\
**Post date:** [October 9, 2016, 6:16am UTC](https://community.plotly.com/t/fixing-x-axis-range-not-working/2347/1 "2016-10-09T06:16:34Z")

</div>

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.

> **[Plunker](http://plnkr.co/edit/mtHNWF4zTBBivmRDnwY2?p=preview)**
>
> Created on Plnkr: Helping developers build the web.

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [October 11, 2016, 8:43pm UTC](https://community.plotly.com/t/fixing-x-axis-range-not-working/2347/2 "2016-10-11T20:43:00Z")

</div>

Here’s how: [http://codepen.io/etpinard/pen/YGLOZm](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()`.

---

<div class="post-metadata">

**Author:** ![abalter](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@abalter](https://community.plotly.com/u/abalter)\
**Post date:** [October 11, 2016, 9:13pm UTC](https://community.plotly.com/t/fixing-x-axis-range-not-working/2347/4 "2016-10-11T21:13:02Z")

</div>

> **[Plunker](http://plnkr.co/edit/91jGHQFXV9MrbayCCiti?p=preview)**
>
> Created on Plnkr: Helping developers build the web.

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 😉

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

```

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