前言
提示:以下是本篇文章正文内容,下面案例可供参考
一、绘制关系图
关系图通常包含节点和边,节点代表某类实体,边代表其相连的节点具有的某种关系。 1.当鼠标悬停在节点上,会隐藏与当前节点非直接连接的节点,而且节点是可以拖动的。
<!DOCTYPE html>
<html>
<head>
<meta charset="'utf-8">
<script src="echarts.min.js"></script>
<script src="dist_echarts-wordcloud.min.js"></script>
</head>
<body>
<div id="main" style="width: 600px; height: 400px;"></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('main'));
var option = {
title: {
text: '关系图',
top: '12%',
left: 'center'
},
label: {
normal: {
show: true
}
},
legend: {
x: 'center',
show: true,
top: '20%',
data: ['男性', '女性']
},
series: [{
type: 'graph',
layout: 'force',
symbolSize: 50,
focusNodeAdjacency: true,
categories: [{
name: '男性',
itemStyle: {
normal: {
color: '#009800',
}
}
}, {
name: '女性',
itemStyle: {
normal: {
color: '#4592FF',
}
}
}],
label: {
normal: {
show: true,
textStyle: {
fontSize: 20
},
}
},
force: {
repulsion: 1000
},
edgeLabel: {
normal: {
show: true,
textStyle: {
fontSize: 10
},
formatter: '{c}'
}
},
data: [{
name: 'A',
category: 0,
draggable: true,
}, {
name: 'B',
category: 1,
draggable: true,
}, {
name: 'C',
category: 0,
draggable: true,
}, {
name: 'D',
category: 1,
draggable: true,
}, {
name: 'E',
category: 0,
draggable: true,
}, {
name: 'F',
category: 1,
draggable: true,
}, {
name: 'G',
category: 0,
draggable: true,
}, {
name: 'H',
category: 1,
draggable: true,
}],
links: [
{
source: 0,
target: 1,
value: '夫妻',
}, {
source: 0,
target: 3,
value: '父子',
}, {
source: 0,
target: 5,
value: '朋友',
}, {
source: 0,
target: 5,
value: '同事',
}, {
source: 0,
target: 7,
value: '夫妻',
}, {
source: 1,
target: 7,
value: '朋友',
}, {
source: 1,
target: 4,
value: '朋友',
}, {
source: 1,
target: 6,
value: '朋友',
}
],
lineStyle: {
normal: {
opacity: 0.9,
width: 3,
curveness: 0
}
}
}
]
};
myChart.setOption(option);
</script>
</body>
</html>
二、可视化图形
|