使用layui封装echarts中的笛卡尔坐标系上的 Graph
时间: 2023-12-11 14:04:48 浏览: 183
ECharts关系图-笛卡尔坐标系上的Graph.rar
layui中封装了echarts,可以直接使用layui的模块加载echarts。然后通过echarts的API来绘制笛卡尔坐标系上的Graph。
首先,在HTML页面中引入layui和echarts的js文件:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Graph</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.6/css/layui.min.css">
</head>
<body>
<div id="main" style="width: 600px;height:400px;"></div>
<script src="https://cdn.staticfile.org/layui/2.5.6/layui.min.js"></script>
<script src="https://cdn.staticfile.org/echarts/4.9.0/echarts.min.js"></script>
<script src="graph.js"></script>
</body>
</html>
```
然后,在graph.js文件中使用layui加载echarts模块,初始化echarts,并绘制Graph:
```javascript
layui.use(['jquery', 'echarts'], function () {
var $ = layui.jquery;
var echarts = layui.echarts;
// 初始化echarts
var myChart = echarts.init(document.getElementById('main'));
// 绘制Graph
myChart.setOption({
title: {
text: 'Graph'
},
tooltip: {},
animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut',
series: [
{
type: 'graph',
layout: 'none',
symbolSize: 50,
roam: true,
label: {
show: true
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [4, 10],
edgeLabel: {
fontSize: 20
},
data: [
{
name: 'node1',
x: 300,
y: 300
},
{
name: 'node2',
x: 800,
y: 300
},
{
name: 'node3',
x: 550,
y: 100
},
{
name: 'node4',
x: 550,
y: 500
}
],
// links表示连接的线
links: [
{
source: 0,
target: 1,
symbolSize: [5, 20],
label: {
show: true
},
lineStyle: {
width: 5,
curveness: 0.2
}
},
{
source: 1,
target: 2,
symbolSize: [5, 20],
label: {
show: true
},
lineStyle: {
width: 5,
curveness: 0.2
}
},
{
source: 2,
target: 3,
symbolSize: [5, 20],
label: {
show: true
},
lineStyle: {
width: 5,
curveness: 0.2
}
},
{
source: 3,
target: 0,
symbolSize: [5, 20],
label: {
show: true
},
lineStyle: {
width: 5,
curveness: 0.2
}
}
]
}
]
});
});
```
运行HTML页面,就可以看到绘制的Graph了。
阅读全文