gpt4 book ai didi

javascript - 绑定(bind)到饼图的点击事件 - Plotly - JavaScript

转载 作者:行者123 更新时间:2023-12-03 01:24:02 27 4
gpt4 key购买 nike

如何转换饼图的plotly绑定(bind)点击事件?

我目前拥有的以下内容是 plotly scatter图表,但我不确定如何将相同的概念用于饼图。

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);
});

最佳答案

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);
});

关于javascript - 绑定(bind)到饼图的点击事件 - Plotly - JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631934/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com