- 由于业务需要使用到echars的插件,自己又不是专业前端,之前没有使用过该插件,所以去官网大概看了一下,echars是一个非常强大的视图插件样式繁多,使用方便灵活,我也去百度浏览了一下一些该插件的使用方法,总结一下,留着以后作为参考,若有哪里写的不对,欢迎指正
- 点击进入echars官网地址
- 该示例需要使用的js
- 前端代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="js/echarts.js"></script>
<title></title>
</head>
<body>
<div id="main" style="width: 100%;height:460px;overflow: hidden;margin: 0;"></div>
<script>
var myChart = echarts.init(document.getElementById('main'));
var graph = {
"nodes":[
{"wordId":150249,"name":"组织相容性试验","value":7},
{"wordId":150253,"name":"血型鉴定和交叉配血","value":9},
{"wordId":150251,"name":"混合淋巴细胞培养试验","value":4},
{"wordId":150252,"name":"血型","value":1},
{"wordId":150250,"name":"免疫学试验","value":8},
{"wordId":150248,"name":"血液交叉配血","value":4}
],
"links":[
{"name":"下位词","source":"组织相容性试验","target":"血液交叉配血"},
{"name":"上位词","source":"组织相容性试验","target":"免疫学试验"},
{"name":"下位词","source":"组织相容性试验","target":"混合淋巴细胞培养试验"},
{"name":"下位词","source":"组织相容性试验","target":"血型"},
{"name":"下位词","source":"组织相容性试验","target":"血型鉴定和交叉配血"},
{"name":"上位词","source":"血液交叉配血","target":"组织相容性试验"},
{"name":"下位词","source":"免疫学试验","target":"组织相容性试验"},
{"name":"上位词","source":"混合淋巴细胞培养试验","target":"组织相容性试验"},
{"name":"上位词","source":"血型","target":"组织相容性试验"},{
"name":"上位词","source":"血型鉴定和交叉配血","target":"组织相容性试验"}
]
}
graph.nodes.forEach(function (node) {
node.itemStyle = null;
node.symbolSize = 40;
node.value = node.label;
node.x = node.y = null;
node.draggable = true;
});
option = {
title: {
text: '知识图谱',
subtext: 'Default layout',
top: 'bottom',
left: 'right'
},
tooltip: {
formatter: function (x) {
return x.data.name;
}
},
animation: true,
series : [
{
name: 'Les Miserables',
type: 'graph',
layout: 'force',
data: graph.nodes,
links: graph.links,
roam: 'true',
lineStyle: {
normal: {
color: '0066cc',
width: '2',
type: 'solid',
opacity: '0.5',
curveness: '0',
},
},
label: {
normal: {
show: true,
textStyle: {
color : '#000000',
fontStyle: 'normal',
fontWeight: 'normal',
fontFamily: '宋体',
fontSize: '15',
},
formatter: function (params) {
if (params.data.name.length > 6) {
return params.data.name.substr(0, 5) + '...';
}
return params.data.name;
}
}
},
force: {
edgeLength: 150,
repulsion: 600,
gravity: 0.1,
layoutAnimation : true,
},
edgeSymbol : [ 'arrow', 'arrow' ],
edgeSymbolSize : '10',
legendHoverLink : true,
itemStyle: {
normal:{
color: function (params){
<!-- var colorList = ['rgb(164,205,438)','rgb(42,170,727)','rgb(25,46,94)','rgb(195,229,235)']; -->
var colorList = ['#11EE3D','#FF0000','#ccffff','#B0E2FF','#55AA88','#9955AA',,'#E6941A',,'33ffff'];
return colorList[params.dataIndex];
}
},
emphasis: {
shadowBlur: '10',
shadowOffsetX: 0,
shadowColor: '#ffff00',
position: 'inside'
},
},
}
]
};
myChart.on('click', function (params){
alert(params.data.name);
top.location.href="www.baidu.com";
});
myChart.setOption(option);
</script>
</body>
</html>
</script>
- 实际效果
- 友情链接
echars配置详解
echars配置