gpt4 book ai didi

javascript - 访问 getTooltipText(e) 事件中的数据行?

转载 作者:行者123 更新时间:2023-11-27 23:48:54 25 4
gpt4 key购买 nike

我使用以下图表:

var data = [
{ Date: "2015-09-14", DayOfMonth: 14, Type: "Views", Amount: 0, y1: 10, },
{ Date: "2015-09-15", DayOfMonth: 15, Type: "Likes", Amount: 1, y1: 15, },
{ Date: "2015-09-16", DayOfMonth: 16, Type: "Likes", Amount: 2, y1: 35, },
{ Date: "2015-09-17", DayOfMonth: 17, Type: "Likes", Amount: 3, y1: 20, },
{ Date: "2015-09-18", DayOfMonth: 18, Type: "Views", Amount: 4, y1: 22, },
{ Date: "2015-09-19", DayOfMonth: 19, Type: "Views", Amount: 5, y1: 22, },
{ Date: "2015-09-20", DayOfMonth: 20, Type: "Views", Amount: 6, y1: 22, },
];


var svg = dimple.newSvg("#chart", svgWidth, svgHeight);
var chart = new dimple.chart(svg, data);
var xAxis = chart.addCategoryAxis("x", "DayOfMonth");
xAxis.title = null;
xAxis.addOrderRule("Date");
var yAxis = chart.addMeasureAxis("y", "Amount");
yAxis.title = null;

var series = chart.addSeries("Type", dimple.plot.area);
series.interpolation = "cardinal";
series.getTooltipText = function(e) {
// need access to Date here
};

在我的工具提示中,我需要该行的“日期”组件,但我只得到“DayOfMonth”和“金额”。

这是一个 JSFiddle:http://jsfiddle.net/93q8pewy/1/

如何从 Tooltip 中的原始数据行获取数据,例如我需要获取 Date

最佳答案

如果您查看传递到回调中的对象e,就会发现有一个名为key 的属性,dimple 使用该属性来唯一标识每个点。考虑到这一点,您可以使用这个拼凑:

series.getTooltipText = function (e) {
var rV = "";
data.forEach(function(d){ //<-- loop data
var u = d.Type + '_' + d.DayOfMonth + '___'; //<-- recreate key
if (u === e.key){ //<-- does it match?
rV = d.Date;
}
});
return [rV]; //<-- show date in tooltip
};

已更新fiddle .

关于javascript - 访问 getTooltipText(e) 事件中的数据行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32887898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com