代码如下:
<template>
<div id="graphEchart" style="width: 800px;height: 400px;" />
</template>
<script>
import * as echarts from 'echarts'
export default {
data() {
return {
graphChart: null
}
},
mounted() {
this.graphEchart = echarts.init(document.getElementById('graphEchart'))
this.drawEchart()
},
methods: {
drawEchart() {
const nodeData = [
{ name: 'Node111', value: [500, 1000] },
{ name: 'Node2', value: [500, 0] },
{ name: 'Node3', value: [300, 0] },
{ name: 'Node4', value: [700, 0] }
]
const linesData = [
{
coords: [
[500, 1000],
[500, 0]
]
},
{
coords: [
[500, 0],
[500, 1000]
]
},
{
coords: [
[700, 0],
[500, 1000]
]
},
{
coords: [
[300, 0],
[500, 0]
]
}
]
const options = {
backgroundColor: 'gray',
title: {
title: '拓扑图'
},
xAxis: {
min: 0,
max: 1000,
show: false,
type: 'value'
},
yAxis: {
min: 0,
max: 1000,
show: false,
type: 'value'
},
series: [
{
type: 'lines',
polyLine: true,
coordinateSystem: 'cartesian2d', // 使用二维直角坐标系
lineStyle: {
type: 'dashed',
width: 2,
color: 'blue',
curveness: 0.05 // 调节线段曲线
},
effect: { // 线效配置
show: true,
trailLength: 0.1,
symbol: 'arrow', // 特效图形标记
color: 'orange',
symbolSize: 8 // 标记的大小
},
data: linesData
},
{
type: 'graph',
coordinateSystem: 'cartesian2d', // 使用二维直角坐标系
layout: 'none',
symbolSize: 50,
roam: true,
label: {
show: true
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [4, 10],
edgeLabel: {
fontSize: 15
},
data: nodeData
}
]
}
this.graphEchart.setOption(options)
}
}
}
</script>
<style lang="scss" scoped>
</style>