简体   繁体   中英

How can I add a trace in Plotly, and set a custom order for each data point along the x axis?

I'm trying to create a line graph that has (x, y) coordinates where the x axis corresponds to a date and the y axis corresponds to a value. The date is formatted DD-MM-YYYY, ie 15-04-2015.

When I add my first trace with something like:

        var trace = {
            x: ["9-10-2016", "6-12-2016", "8-12-2016"],
            y: [30, 11, 38],
            name: "trace 1",
        mode: 'lines

, I simply sort my array for the x axis and y axis by date using a custom sort method for a javascript array.

But when I add a new trace to the graph, there doesn't seem to be an obvious way to have the points ordered by date relative to the other traces on the graph. They seem to always be to the right of everything on the first trace, even if some of the points in the second trace have dates that are earlier than the dates in the first trace.

How are you implementing your custom sort method for the x-axis? Is this something that Plotly supports? I didn't see any documentation for this.

According to this page , Plotly's date format is yyyy-mm-dd HH:MM:SS.ssssss .

I would try to have the data for the x-axis match this format and see if it resolves your problem. If it doesn't resolve your problem, it would be helpful to have a JSFiddle that demonstrates the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM