# Scatterplot Using Dates on the X-Axis line messed up

**URL:** <https://community.plotly.com/t/scatterplot-using-dates-on-the-x-axis-line-messed-up/6212>\
**Category:** plotly.js\
**Created:** [October 11, 2017, 9:49am UTC](https://community.plotly.com/t/scatterplot-using-dates-on-the-x-axis-line-messed-up/6212 "2017-10-11T09:49:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schorry92](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Schorry92](https://community.plotly.com/u/Schorry92)\
**Post date:** [October 11, 2017, 9:49am UTC](https://community.plotly.com/t/scatterplot-using-dates-on-the-x-axis-line-messed-up/6212/1 "2017-10-11T09:49:17Z")

</div>

Hi,

I have a plot as shown in [Using Dates on the X-Axis](https://plot.ly/javascript/axes/).  
My dates are not inserted in a specific order, but I’d like to have a chronological line through all date points.  
Instead I get a line that follows the order of the dates in the trace.

Is there an easy way to handle this or do I have to sort x and y traces by the dates in x before plotting?

Thanks in advance,  
Rena

---

<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, 2017, 2:17pm UTC](https://community.plotly.com/t/scatterplot-using-dates-on-the-x-axis-line-messed-up/6212/2 "2017-10-11T14:17:06Z")

</div>

Plotly doesn’t expose an attribute that does that. You can use the native JS `.sort` array function to do so.

Something like:

```auto
{
  x: dates.sort(function (a, b) { new Date(a).getTime() - new Date(b).getTime() })
}

```

should do the trick.
