Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Go back to previous view plotly JS

I have a plot which looks like:

Stacked time series plot.

The x-axis is shared and the y-axes are not. I currently have a code which when double-clicking a trace in the legend will delete the other two traces and show only the one trace. Here is the relevant code:

var myPlot = document.getElementById('graph');          
            myPlot.on('plotly_legenddoubleclick', function(data){
                var trace = data.curveNumber + 1;
                
                if (trace == 1 && flag2 == 0) {
                    var layout_update = {title: "Historical Trend", autosize: true, xaxis: {title:"Date", type: "date", rangeselector: {buttons: [{count: 1,label: '1m',step: 'month',stepmode: 'backward'},{count: 3,label: '3m',step: 'month',stepmode: 'backward'},{count: 6,label: '6m',step: 'month',stepmode: 'backward'},{step: 'all'}]}},yaxis: {title:"Vertical",fixedrange: true}};
                    Plotly.update('graph', layout_update);
                    Plotly.deleteTraces('graph', 1);
                    Plotly.deleteTraces('graph', 1);
                    flag2 = 1;
                
                }
                
                else if (trace == 2 && flag2 == 0) {
                    var layout_update = {title: "Historical Trend", autosize: true, xaxis: {title:"Date", type: "date", rangeselector: {buttons: [{count: 1,label: '1m',step: 'month',stepmode: 'backward'},{count: 3,label: '3m',step: 'month',stepmode: 'backward'},{count: 6,label: '6m',step: 'month',stepmode: 'backward'},{step: 'all'}]}},yaxis: {title:"Horizontal",fixedrange: true}};
                    Plotly.update('graph', layout_update);
                    Plotly.deleteTraces('graph', 0);
                    Plotly.deleteTraces('graph', 1);
                    flag2 = 1;
                    
                }
                
                else if (trace == 3 && flag2 == 0) {
                    var layout_update = {title: "Historical Trend", autosize: true, xaxis: {title:"Date", type: "date", rangeselector: {buttons: [{count: 1,label: '1m',step: 'month',stepmode: 'backward'},{count: 3,label: '3m',step: 'month',stepmode: 'backward'},{count: 6,label: '6m',step: 'month',stepmode: 'backward'},{step: 'all'}]}},yaxis: {title:"Axial",fixedrange: true}};
                    Plotly.update('graph', layout_update);
                    Plotly.deleteTraces('graph', 0);
                    Plotly.deleteTraces('graph', 0);
                    flag2 = 1;
                
                }

});

I want to include a clause with flag == 1 that will return the view to the 3 plot view. How can I do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!