Skip to content

Ghost plot using 2 y-axis chart #92

@jonfreedman

Description

@jonfreedman

I am working on an application which allows charting of multiple timeseries and selecting whether to display them on a left or right y-axis. I have written my own react component which uses react-plotly.js and data and layout props are created within the render method. I seem to reliably be able to produce this chart where the top blue line is ghosted by updating my state from a 1-item data array with yaxis: 'y' to a 2-item with yaxis: 'y' to a 2-item with 1x yaxis: 'y' and 1x yaxis: 'y2'. I'm not sure if this is a bug or if I have misconfigured multiple axes (based on https://plot.ly/javascript/multiple-axes/)

plotly-chart

When I build the data array I set the yaxis parameter to either 'y' or 'y2' e.g.

{
    hoverinfo: 'x+y+text',
    mode: 'lines',
    name: label,
    type: 'scatter',
    x: params.data.keySeq().map((date)=>DateTimeFormatter.ISO_LOCAL_DATE.format(date)).toArray(),
    y: params.data.valueSeq().toArray(),
    yaxis: params.yaxis==='left'?'y': 'y2'
}

My layout:

{
    annotations: [{
        ax: 0,
        captureevents: true,
        text: 'BOE-25bp',
        x: '2016-08-04',
        y: 0
    },
    {
        ax: 0,
        captureevents: true,
        text: 'BOE+25bp',
        x: '2017-11-02',
        y: 0
    }],
    height: 800,
    width: this.state.chartWidth,
    xaxis: {
        range: [DateTimeFormatter.ISO_LOCAL_DATE.format(this.state.chartOptions.startDate()),
        DateTimeFormatter.ISO_LOCAL_DATE.format(this.state.chartOptions.endDate)],
        type: 'date'
    },
    yaxis: {
        side: 'left',
        
    },
    yaxis2: {
        overlaying: 'y'as'/^y([2-9]|[1-9][0-9]+)?$/',
        side: 'right'
    }
}

Props via the react chrome debugger shown below:
plotly-debug

I also exported the data here:
https://plot.ly/~jfreedman/1/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions