1

我目前正在尝试将 json 文件的数字和日期(字符串格式)显示到提示工具提示中。

数据 =[{"日期":["2010-07-01","2010-07-02","2010-07-03","2010-07-04","2010-07-05"," 2010-07-06","2010-07-07","2010-07-08","2010-07-09","2010-07-10","2010-07-11","2010- 07-12","2010-07-13","2010-07-14","2010-07-15","2010-07-17","2010-07-18","2010-07- 19","2010-07-20","2010-07-21","2010-07-23","2010-07-24","2010-07-26","2010-07-27" ,"2010-07-28","2010-07-29","2010-07-30","2010-07-31"],"收视率":[3.29, 3.8, 4.67, 4.17, 3.33, 4.25 , 4.0, 4.0, 3.83, 3.67, 3.25, 4.0, 4.5, 3.67, 4.33, 4.0, 4.0, 3.0, 4.5, 4.0, 4.0, 4.0, 4.4, 4.0, 4.25, 4.0, 4.0, 4.0]}]

            var w = data[0].ratings.length,
            h = 20;

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

            vis.add(pv.Bar)
            .data(data[0].ratings)
            .width(4)
            .left(function() 5 * this.index)
            .height(function(d) Math.round(d))
            .bottom(0)
            // I need the "num" to be dynamic, meaning getting the current count of the                bar position when doing a mouseover.
            .text(function(d) "Date: " +data[0].dates[num] + " Average Rating: "+ d)
            .event("mouseover", pv.Behavior.tipsy({gravity: "s", fade: true }));     

            vis.add(pv.Rule)
            .bottom(12)
            .strokeStyle("red")

            vis.render();

我需要 data[0].dates[num] 中的 num 是动态的,这意味着当我在显示的栏上进行鼠标悬停时,它将获取栏的计数。我的主要目的是让工具提示一起显示收视率和日期。例如,如果 num 为 1,它将显示 2010-07-01 等等...

任何人都可以摆脱一些方法来实现我的目标吗?

4

1 回答 1

1

你想要的this.index财产:

data[0].dates[this.index]

看到整个事情的行动

于 2011-07-26T17:49:27.863 回答