- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
下面是JSON数据:
var IDData = JSON.stringify([
["C2", "ID2", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 2],
["C2", "ID2", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 700.0, 3],
["C2", "C3", "Customer", "Customer", "2015-1-1", "2015-1-1", 500.0, 2],
["C2", "C3", "Customer", "Customer", "2015-1-2", "2015-1-3", 600.0, 2],
["C6", "C1", "Customer", "Customer", "2015-1-1", "2015-1-1", 500.0, 1],
["C5", "ID4", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 2],
["C1", "ID1", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 1],
["C1", "P1", "Customer", "Phone", "2015-1-1", "2015-1-1", 500.0, 1],
["C6", "P2", "Customer", "Phone", "2015-1-1", "2015-1-1", 500.0, 2],
["C6", "P2", "Customer", "Phone", "2015-1-3", "2015-1-4", 800.0, 2],
["C2", "C6", "Customer", "Customer", "2015-1-1", "2015-1-1", 500.0, 1],
["C4", "C3", "Customer", "Customer", "2015-1-1", "2015-1-1", 500.0, 3],
["C1", "C2", "Customer", "Customer", '2015-1-1', "2015-1-1", 500.0, 1],
["C4", "ID3", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 3],
["C3", "ID3", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 3],
["C1", "C5", "Customer", "Customer", "2015-1-1", "2015-1-1", 500.0, 1]
]);
我正在迭代此 JSON 数据,将其转换为适合制作图表的格式,如下所示:
var galData = JSON.parse(IDData);
var startnodes = [];
var endnodes = [];
var startnodetype = [];
var endnodetype = [];
var SendTime = [];
var PayTime = [];
var Total_Amt = [];
var Depth = [];
galData.map(function(e, i) {
startnodes.push(e[0]);
endnodes.push(e[1]);
startnodetype.push(e[2]);
endnodetype.push(e[3]);
SendTime.push(e[4]);
PayTime.push(e[5]);
Total_Amt.push(e[6]);
Depth.push(e[7]);
});
var final_data = createNodes(startnodes, endnodes, startnodetype, endnodetype, SendTime, PayTime, Total_Amt, Depth);
makeGraph("#Network_graph", final_data);
createNodes()函数如下:
function createNodes(startnodes, endnodes, startnodetype, endnodetype, SendTime, PayTime, Total_Amt, Depth) {
var node_set = [];
var links = [];
var nodetype = d3.set();
startnodes.forEach(function(src, i) {
var tgt = endnodes[i];
if (!node_set.find(function(d) {
return d.id == src
})) {
node_set.push({
id: src,
type: startnodetype[i]
});
}
if (!node_set.find(function(d) {
return d.id == tgt
})) {
node_set.push({
id: tgt,
type: endnodetype[i]
});
}
links.push({
source: src,
target: tgt,
sendtime: SendTime[i],
paytime: PayTime[i],
total_amt: Total_Amt[i],
depth: Depth[i],
value: 1
});
});
startnodetype.forEach(function(src, i) {
var tgt_type = endnodetype[i];
nodetype.add(src);
nodetype.add(tgt_type);
});
var d3GraphData = {
nodes: node_set.map(function(d) {
return {
id: d.id,
type: d.type,
group: 1
}
}),
links: links,
nodetype: nodetype.values().map(function(d) {
return {
id: d.id,
group: 1
}
})
}
return d3GraphData;
};
在我的 makeGraph() 函数中,我可以使用工具提示将鼠标悬停在节点和链接上时显示文本:
我显示
nodes: d.id and d.type,
links: d.paytime,d.Sendtime,d.Amount and d.depth
下面是代码:
var tooltip = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var link = svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(d3GraphData.links)
.enter().append("line")
.attr("stroke-width", function(d) {
return Math.sqrt(d.value);
})
.on('mouseover', function(d) {
tooltip.transition()
.duration(300)
.style("opacity", .8);
tooltip.html("<p/>Paytime:" + d.paytime + "<p/>Amount:" + d.total_amt + "<p/>SendTime:" + d.sendtime + "<p/>Depth" + d.depth)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 10) + "px");
})
.on("mouseout", function() {
tooltip.transition()
.duration(100)
.style("opacity", 0);
})
.on("mousemove", function() {
tooltip.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 10) + "px");
});
var node = svg.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(d3GraphData.nodes)
.enter().append("circle")
.attr("r", 5)
.attr("fill", function(d) {
return color(d.type);
})
.on('mouseover', function(d) {
tooltip.transition()
.duration(300)
.style("opacity", .8);
tooltip.html(d.id + "<p/>type:" + d.type)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 10) + "px");
})
.on("mouseout", function() {
tooltip.transition()
.duration(100)
.style("opacity", 0);
})
.on("mousemove", function() {
tooltip.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 10) + "px");
})
此代码工作正常,并且在将鼠标悬停在链接上时显示文本。
但考虑到这种情况:
["C2", "ID2", "Customer", "ID_Card", "2015-1-1", "2015-1-1", 500.0, 2],
["C2", "ID2", "Customer", "ID_Card", "2015-1-2", "2015-1-3", 700.0, 2]
此处,节点“C2”和“ID2”之间有 2 次交互,但将鼠标悬停在链接上时,工具提示会显示以下内容:
PayTime: 2015-1-3
Amount: 700
SendTime: 2015-1-2
Depth: 3
理想情况下,我希望它显示如下内容:以便捕获它们之间交互的数据。
PayTime: 2015-1-3
Amount: 700
SendTime: 2015-1-2
Depth: 3
PayTime: 2015-1-1
Amount: 500
SendTime: 2015-1-1
Depth: 2
以下是 fiddle 的链接
最佳答案
如果您检查力图,您会发现,对于您提到的特定链接(C2 到 ID2),您有两条线。当您将鼠标悬停在链接上时,您只会获得有关顶行(触发鼠标悬停的那一行)的信息。
这个问题有一个解决方案。在鼠标悬停(或鼠标移动,这并不重要)内,创建一个函数来获取有关这两个节点(源和目标)的所有数据。这是函数:
.on('mouseover', function(d) {
var thisSource = d.source.id,
thisTarget = d.target.id;
var filteredLinks = d3GraphData.links.filter(function(e) {
return (e.source.id === thisSource && e.target.id === thisTarget)
|| (e.source.id === thisTarget && e.target.id === thisSource);
});
此函数创建一个名为 filteredLinks
的新数组,其中包含您需要的所有数据。例如,如果您将鼠标悬停在您提到的链接上,您会得到以下结果:
[{
"source": {
"id": "C2",
"type": "Customer",
"group": 1,
"index": 0,
"x": 405.82425848083665,
"y": 335.62277280058106,
"vy": -0.0002356554712780902,
"vx": 0.00011724088097396833
},
"target": {
"id": "ID2",
"type": "ID_Card",
"group": 1,
"index": 1,
"x": 387.34926064098437,
"y": 307.0409186320801,
"vy": -0.000681439057517941,
"vx": 0.0008168234236215556
},
"sendtime": "2015-1-1",
"paytime": "2015-1-1",
"total_amt": 500,
"depth": 2,
"value": 1,
"index": 0
}, {
"source": {
"id": "C2",
"type": "Customer",
"group": 1,
"index": 0,
"x": 405.82425848083665,
"y": 335.62277280058106,
"vy": -0.0002356554712780902,
"vx": 0.00011724088097396833
},
"target": {
"id": "ID2",
"type": "ID_Card",
"group": 1,
"index": 1,
"x": 387.34926064098437,
"y": 307.0409186320801,
"vy": -0.000681439057517941,
"vx": 0.0008168234236215556
},
"sendtime": "2015-1-2",
"paytime": "2015-1-3",
"total_amt": 700,
"depth": 3,
"value": 1,
"index": 1
}]
现在,只需使用过滤后的数组来填充您的工具提示。由于这是大量工作,我会将这部分留给您......
PS:但是,最好的解决方案是不要在第一个地方有两条重叠的线。为了解决这个问题,您可以在绘制图表之前在链接数组中搜索重复项并合并它们。
关于javascript - 力导向图上的 d3.js 工具提示在将鼠标悬停在链接上时不显示完整数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41253681/
我的 friend 编写了一个程序,它比较随机排列的骰子面,以找到分布最均匀的面——尤其是当面不仅仅是序列时。 我将他的程序翻译成 haskell 是因为我一直在寻找一个理由来让别人知道 haskel
我需要对表单中的某些字段进行评论/提示。我的想法是在模型中描述它,就像attributeLabels一样。我该怎么做? 然后它会是理想的,如果 Gii 模型(和 Crud)生成器直接从 mysql 列
我们使用 FastReport 来生成报告。事实上,我们为访问源代码付费。 我们目前使用的是 FastReport 的最新稳定版本。虽然它对于我们的生产来说足够稳定,但每当我编译时,我都会看到以下内容
我需要创建一个对话框/提示,包括用于用户输入的文本框。我的问题是,确认对话框后如何获取文本?通常我会为此创建一个类,将文本保存在属性中。不过我想使用 XAML 设计对话框。因此,我必须以某种方式扩展
我想提示用户是否要执行操作(删除) - 用警报框说"is"或“否”,如果是,则运行删除脚本,如果否,则不执行任何操作 我不太了解 javascript,因此是否有人可以使用 javascript 获得
所以我正在编写一个简单的 JS 代码。我们刚刚开始学习函数。我需要创建一个名为“printStars”的函数。 我需要从用户那里获取一个号码,并根据该号码打印“*”。 这就是我所做的:
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我正在自定义我的 zsh 提示,并发现以下内容来检查是否有任何后台作业: if [[ $(jobs | wc -l) -gt 0 ]]; then # has background job(s)
这个问题在这里已经有了答案: JavaScript object: access variable property by name as string [duplicate] (3 个答案) pa
我正在尝试用 javascript 制作一个简单的数学练习程序。在提示警报中给出不同的值,并将答案与用户输入进行比较。这是代码: Calculations generate(); functio
在这段代码中,尽管我使用了文本对齐属性在“编辑文本” View 的中心设置“提示”。但它无法正常工作。 最佳答案 尝试 关于android - 如何在编辑文本的中心对齐文本(提示),我们在Sta
我正在尝试让我的 EditText 显示一个提示,例如“请在此处输入答案”,当用户点击 EditText 以键入他们的答案时,文本应该消失并留空,以便他们在其中输入答案. 截至目前,这就是我的 .xm
我当前的 android 应用程序中有两个微调器,我想要一个默认值,例如 editText 的 android:hint 功能。有没有办法这样做,但不会将提示添加到填充微调器的字符串数组。例如从微调器
如果我的表单已完全填写,我如何提示“感谢您填写表单,“name”!” function submit_onclick() { if(confirm("Thanks for completing t
我刚刚了解了prompt()命令;我知道 Prompt() 命令以字符串的形式返回用户输入。我正在搞乱下面的程序,我输入了Per“Dead”Ohlin作为男性名字。为什么这有效并且没有引起任何问题?
void openUpNow(FILE *x, FILE *y) { x = fopen("xwhatever", "r"); y = fopen("ywhatever", "r");
我有一个作业正在处理,但我在使用 prompt() 方法时遇到了问题。我看到我可以做一个提示,但我需要几个并且有数量。 例如... 我创建了一个 HTML 表格,其中包含许多艺术家和包含 DVD、CD
我正在学习 Big Nerd Ranch 的 iOS Programming, 2nd Edition,我已经来到第 4 章挑战:标题。该练习暗示我感到困惑;它说我需要做一些我认为不需要做的事情。 到
抱歉,如果这是微不足道的,但我没有找到任何解决此问题的建议。我在 Ubuntu 上,我的 Yii 项目需要 PHPUnit。我已经安装了 PHPUnit 两次,方法是下载 phpunit.phar 并
我是一名优秀的程序员,十分优秀!