我目前正在尝试将json文件的数量和日期(字符串格式)显示为醉意的工具提示。
data = [{“dates”:[“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.6,3.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();
我需要数据[0] .dates [num]中的num是动态的,这意味着当我在显示的栏上执行鼠标悬停时,它将获得条的计数。我的主要目的是让工具提示一起显示评级和日期。例如,如果num为1,它将显示2010-07-01,依此类推......
任何人都可以通过某种方式实现我的目标吗?