1

我在我的图表上喝醉了。该mouseover事件运行良好,但是当我添加一个click事件时,它并没有click按照我的意愿执行该事件。

下面是我的代码:

var vis = new pv.Panel()
            .width(w)
            .height(h);

            vis.add(pv.Bar)
            .data(data)
            .width(4)
            .left(function() 5 * this.index)
            .height(function(d) Math.round(d*4))
            .bottom(0)
            .text(function(d) d.toFixed(1))
            .event("mouseover", pv.Behavior.tipsy({gravity: "w", fade: true}))
            //If I remove the mouseover event, the click event will work but not when both are veing put together.
            .event("click", function() self.location = "http://stanford.edu");

            vis.render();

谁能帮我解决这个问题?

4

1 回答 1

2

这是一种解决方法。您可以将点击回调函数传入 pv.Behavior.tipsy 并在其中调用点击事件。

  1. 修改 pv.Behavior.tipsy(...) 以传入回调函数:

    pv.Behavior.tipsy = 函数(选择,回调)

  2. 修改事件调用以传入回调函数:

    .event("mouseover", pv.Behavior.tipsy({gravity: "w", fade: true}, function(){alert('click call back');}))

  3. 修改protovis.tipsy.js中return函数的最后一行:

    return function(d) { .... $(tip).mouseleave(cleanup).tipsy("show"); if(callback) { $(tip).click(callback); } };

于 2011-09-20T22:01:22.360 回答