Skip to content

No Click event on category label (xticks) of bar chart #1751

@patilkun

Description

@patilkun

I am not getting click event on click of category label (xticks) of bar chart. I am using 'plotly_click'.
Below is the code

HTML -

<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
  
  <div id="myDiv" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>
  <script>
    <!-- JAVASCRIPT CODE GOES HERE -->
  </script>
</body>

Javascript -

var trace1 = {
  x: ['giraffes', 'orangutans', 'monkeys'], 
  y: [20, 14, 23], 
  name: 'SF Zoo', 
  type: 'bar'
};

var trace2 = {
  x: ['giraffes', 'orangutans', 'monkeys'], 
  y: [12, 18, 29], 
  name: 'LA Zoo', 
  type: 'bar'
};

var data = [trace1, trace2];

var layout = {barmode: 'group'};

Plotly.newPlot('myDiv', data, layout);
var myDiv = document.getElementById('myDiv');
myDiv.on('plotly_click', function(data){
    alert('chart clicked');
});

I am able to get click event on actual bars but I am looking for click event on category label under bar.
In below image I am looking for click event on 'giraffes'. Thanks for the help in advance.
image

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