首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Plotly.js单击事件

Plotly.js单击事件
EN

Stack Overflow用户
提问于 2015-10-19 11:01:42
回答 1查看 5.6K关注 0票数 1

我正在用Plotly写一个网页。问题是,当我使用Plotly_onclick事件时,似乎出现了一些问题。具体地说,当我用鼠标点击时,它没有反应。当我使用笔记本电脑的触摸板点击时,也就是按下触摸板,它也没有反应。只有当我用力触摸我的触摸板时,它才会做出反应。我处理不了这个问题。有没有人知道怎么修?

click事件的代码如下:

代码语言:javascript
复制
.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);

    })
EN

回答 1

Stack Overflow用户

发布于 2016-07-15 18:16:20

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

代码:

代码语言:javascript
复制
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);
});

它有一些泻湖,但它是一个事件的开始...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33205978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档