散点图实现拓扑图

本文介绍如何利用Vue.js实现拓扑图的绘制。在数据中没有指定位置的情况下,通过计算处理数据,区分单个设备和多个设备的情况,它们都隶属于同一个网关。内容包括HTML布局、数据处理和画图的步骤,最终展示清晰的拓扑散点图效果。
摘要由CSDN通过智能技术生成

 

1.返回的数据

this.subDevice = [{
    "id": "873736ed2b860ad256f2e105d2fb2865",
    "name": "设备1",
    "online": 0
},
{
    "id": "663b4d95d94bc782fcd3a55b3bf119cc",
    "name": "设备2",
    "online": 0
},
{
    "id": "aaa3f9205d1850adb18ea763545855bf",
    "name": "设备3",
    "online": 0
}]

2.因为没有位置返回,所以需要自己计算,就是两种情况,一个返回设备,和多个返回设备,设备从属网关都是一个。

html及琐碎

<div :style="{ height: cellHeight, width: '100%' }" id="Topology"></div>

myChart: null,
chartData: {},
cellHeight: '300px',
getwayimg: "图片地址",
subdeviceimg: 图片地址",
closeimg: 图片地址"


this.cellHeight = document.body.offsetHeight - 300 + 'px'

数据处理画图 

        
        draw() {
            this.chartData = [
                {
                    type: 'scatter',
                    symbolSize: 35, //大小
                    zlevel: 20,
                    symbol: 'image://' + this.getwayimg, //图标
                    data: [
                        {
                            name: this.gateway.name, //名称
                            value: [0, 50] //位置
                        }
                    ],
                    itemStyle: {
                        opacity: 1
                    },
                    label: {
                        show: true,
                        formatter: '{b}',
                        offset: [0, 40],
                        color: '#333333'
                    }
                }
            ]

            if (this.subDevice.length === 1) {
                let tempLine = {
                    type: 'lines', // 连接线
                    coordinateSystem: 'cartesian2d',
                    zlevel: 1,
                    polyline: true,
                    lineStyle: {
                        width: 1,
                        type: 'dotted',
                        color:
                            this.subDevice[0].online !== 1
                                ? '#ff0000'
                                : '#12A7FF',
                        opacity: 1
                    },
                    data: [
   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值