我在这里找到了一个 d3.js 和弦示例。不幸的是,我不明白如何将他的以下矩阵更改为我的数据。
var matrix = [
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], // Bob
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], // Giovanni
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], // Steve
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], // Kevin
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], // Art
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], // Pyotr
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], // Rohan
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], // Rachel
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // Sasha
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], // Emily
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], // Lee
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], // Viva
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] // Poh
]
我的数据分为 2 个 json 文件。第一个描述圆圈标签、颜色和大小
[
{
"color": "#996600",
"id": "chr03",
"len": 35020413,
"label": "chr03"
},
{
"color": "#666600",
"id": "tig00007144",
"len": 40868,
"label": "tig00007144"
},
{
"color": "#666600",
"id": "tig00026480",
"len": 95961,
"label": "tig00026480"
},
...
]
另一方面,第二个文件描述了和弦图中每个标签之间的关系。
[
{
"source": {
"start": 30824,
"end": 23113,
"id": "tig00007144"
},
"target": {
"start": 33203431,
"end": 33211142,
"id": "chr03"
}
},
{
"source": {
"start": 48387,
"end": 1,
"id": "tig00026480"
},
"target": {
"start": 35010628,
"end": 34962190,
"id": "chr03"
}
},
...
]
如何将上述关系文件转换为适当的矩阵?
先感谢您。