javascript - Plotly.js 点击事件

标签 javascript onclick html plotly

我正在使用 Plotly 编写网页。问题是,当我使用 Plotly_onclick 事件时,似乎出现了问题。 具体来说,当我使用鼠标单击时,它没有反应。当我使用笔记本电脑的触摸板单击时,即按下触摸板时,它也没有反应。只有当我用力触摸触摸板时,它才会有反应。 我不能处理这个。有谁知道怎么解决吗?

点击事件的代码在这里:

.on('plotly_click', function (event, eventdata) {

        var point = eventdata.points[0];

        var traceColor = point.fullData.marker.color,
            newAnnotation = {
                x: point.xaxis.d2l(point.x),
                y: point.yaxis.d2l(point.y),
                ax: 0,
                ay: -50,
                arrowhead: 6,
                bgcolor: 'rgba(255,255,255,0.75)',
                arrowcolor: traceColor,
                font: {color: traceColor},
                text: point.data.name + ':' + point.y + 'on ' + point.x
            },
            newIndex = (rangePlot.layout.annotations || []).length;
            console.log(newIndex);

        var TextFromUser = {name: point.data.name, time: point.x, value: point.y};

        if(TextFromUser['time'].length==10)
        {
            TextFromUser['time']=TextFromUser['time']+' 00:00';
        }
        else if(TextFromUser['time'].length==13)
        {
            TextFromUser['time']=TextFromUser['time']+':00';
        }
        else;



        if (newIndex) {

            var foundCopy = false;
            rangePlot.layout.annotations.forEach(function (ann, sameIndex) {
                if (ann.text === newAnnotation.text) {
                    Plotly.relayout(rangePlot, 'annotations[' + sameIndex + ']', 'remove');
                    foundCopy = true;
                }
            });
            if (foundCopy) return;
        }

        Plotly.relayout(rangePlot, 'annotations[' + newIndex + ']', newAnnotation);

    })

最佳答案

示例引用: https://plot.ly/javascript/click-events/

代码:

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

它有一些泻湖,但这是事件发生的开始......

关于javascript - Plotly.js 点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205978/

相关文章:

javascript - 数组递增 Javascript/node js/mongodb

jquery - 点击其他图片后如何获取图片src

javascript - 如何添加指向外部 ".html"的灯箱中打开的图像的链接?

javascript - Gulp:合并文件

javascript - 测试组件时覆盖管道

javascript - 动态键名

javascript - 使用 JQuery 将值从表复制到模态

javascript Uncaught ReferenceError onclick

javascript - 更好地测试 base64 URI 支持(我可以在 JS 中创建一个大的 base64 编码图像吗?)

html - 在图像下添加文本(左、中、右)