Skip to content

Using "plotly_selected" failed #1793

@wilsonandusa

Description

@wilsonandusa

I want the plot to respond with an alert message when the user selects some data(zoom in), but the following example does not responds with user selection.

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>


</head>
<body>
  <div id = "tester_1"></div>


  <script>


  TESTER_1 = document.getElementById('tester_1');

  var trace1 = {
    x: [1,2,3,4,5,6,7,8,9,10,11],
    y: [1,2,3,3,4,4,4,5,5,5,5],
    mode: 'lines'

  };
  var data = [trace1]
  var layout = {

    displaylogo:false,
    xaxis: {
      title: 'x'
    },
    yaxis: {
     title:'y'
    }
  }
  Plotly.newPlot( TESTER_1, data, layout, {modeBarButtonsToRemove: ['toImage','sendDataToCloud','hoverCompareCartesian','pan2d',
   'zoom2d','select2d','lasso2d','resetScale2d','hoverClosestCartesian',],displaylogo:false})
    document.getElementById('tester_1').on('plotly_selected', function(data){
       console.log('clicked')
        alert('Clicked');
    })

  </script>
</body>
</html>

Also, I wonder if there's a function to detect which modebar button the user clicked. For example, if the user clicks the autoscale button, the plots shows an alert message "Autoscale finished!".

Thanks

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