ARTLoe
ARTLoe

Reputation: 1799

Binding to Click Events for Pie Chart - Plotly - JavaScript

How to convert the plotly binding click event for a pie chart?

What I currently have below is for a plotly scatter graph, but I am unsure how to use the same concept for a pie chart.

var myPlot = document.getElementById('myDiv'),
    d3 = Plotly.d3,
    N = 16,
    x = d3.range(N),
    y = d3.range(N).map( d3.random.normal() ),
    data = [ { x:x, y:y, type:'scatter',
            mode:'markers', marker:{size:16} } ],
    layout = {
        hovermode:'closest',
        title:'Click on Points'
     };

Plotly.newPlot('myDiv', data, layout);

myPlot.on('plotly_click', function(data){
    var pts = '';
    for(var i=0; i < data.points.length; i++){
        pts = 'x = '+data.points[i].x +'\ny = '+
            data.points[i].y.toPrecision(4) + '\n\n';
    }
    alert('Closest point clicked:\n\n'+pts);
});

Upvotes: 0

Views: 1999

Answers (1)

ARTLoe
ARTLoe

Reputation: 1799

myPlot.on('plotly_click', function(data){
    var pts = '';
    for(var i=0; i < data.points.length; i++){
        pts = 'label(country) = '+ data.points[0].label + '\nvalue(%) = ' + data.points[0].value;
    }
    alert('Closest point clicked:\n\n'+pts);
});

Upvotes: 0

Related Questions