Toggle navigation
原型用途
By
o***兔
2020-03-09 12:41:23
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
/* 【备注】 转载于x丝男爵,感谢提供资源 并在此基础修改保存 内容说明: 由于不知道是不是echart版本问题导致在这官网demo中不能拖拽, 但本地亲测可以,这里的代码也可以作为参考,欢迎改进 另博客地址: https://blog.csdn.net/u012138137/article/details/89456199 **/ var nodes = [{ x: '6', y: '7', name: '当前设备', img: 'data-1547632686885-o5Rfi3tyk.png', }, { x: '3', y: '9', name: '设备A', img: 'data-1547632686885-o5Rfi3tyk.png', }, { x: '3', y: '5', name: '设备B', img: 'data-1547632686885-o5Rfi3tyk.png', }, { x: '9', y: '9', name: '设备C', img: 'data-1547632686885-o5Rfi3tyk.png', }, { x: '9', y: '5', name: '设备D', img: 'data-1547632686885-o5Rfi3tyk.png', } ] var links = [{ source: '当前设备', target: '设备B', name: '' }, { source: '当前设备', target: '设备A', name: '' }, { source: '当前设备', target: '设备C', name: '' }, { source: '当前设备', target: '设备D', name: '' } ] var charts = { nodes: [], links: [], linesData: [] } var dataMap = new Map() for (var j = 0; j < nodes.length; j++) { var x = parseInt(nodes[j].x) var y = parseInt(nodes[j].y) var node = { name: nodes[j].name, value: [x, y], symbolSize: 50, alarm: nodes[j].alarm, symbol: 'image:///asset/get/s/' + nodes[j].img, itemStyle: { normal: { color: '#12b5d0', } } } dataMap.set(nodes[j].name, [x, y]) charts.nodes.push(node) } for (var i = 0; i < links.length; i++) { var link = { source: links[i].source, target: links[i].target, label: { normal: { show: true, formatter: links[i].name } }, lineStyle: { normal: { color: '#12b5d0' } } } charts.links.push(link) // 组装动态移动的效果数据 var lines = [{ coord: dataMap.get(links[i].source) }, { coord: dataMap.get(links[i].target) }] charts.linesData.push(lines) } option = { tooltip: { trigger: 'item', formatter: '{b}', }, backgroundColor: "#ffffff", xAxis: { min: 0, max: 12, show: false, type: 'value' }, yAxis: { min: 0, max: 12, show: false, type: 'value' }, series: [{ type: 'graph', layout: 'none', id: 'a', coordinateSystem: 'cartesian2d', edgeSymbol: ['', 'arrow'], // symbolSize: 50, label: { normal: { show: true, position: 'bottom', color: '#12b5d0' } }, lineStyle: { normal: { width: 2, shadowColor: 'none' } }, xAxis: { min: 0, max: 12, show: false, type: 'value' }, yAxis: { min: 0, max: 12, show: false, type: 'value' }, // edgeSymbolSize: 8, draggable: true, data: charts.nodes, links: charts.links, z: 4, itemStyle: { normal: { label: { show: true, formatter: function(item) { return item.data.name } } } } }, { name: 'A', type: 'lines', coordinateSystem: 'cartesian2d', z: 4, effect: { show: true, trailLength: 0, symbol: 'arrow', color: '#12b5d0', symbolSize: 8 }, lineStyle: { normal: { curveness: 0 } }, data: charts.linesData, }] }; myChart.setOption(option); myChart.on('click', function(param) { var nodeses = [{ x: '1', y: '12', name: 'DNS', img: 'data-1547632686885-o5Rfi3tyk.png', }, { x: '1', y: '3', name: '爬虫数据', img: 'data-1547632686885-o5Rfi3tyk.png', } ] var linkses = [{ source: 'DNS', target: '爬虫数据', name: '访问' } ] console.info(1) var chartses = { nodeses: [], linkses: [], linesDataes: [] } var dataMapes = new Map() for (var j = 0; j < nodeses.length; j++) { var x = parseInt(nodeses[j].x) var y = parseInt(nodeses[j].y) var node = { name: nodeses[j].name, value: [x, y], symbolSize: 50, alarm: nodeses[j].alarm, symbol: 'image:///asset/get/s/' + nodeses[j].img, itemStyle: { normal: { color: '#12b5d0', } } } dataMapes.set(nodeses[j].name, [x, y]) chartses.nodeses.push(node) } for (var i = 0; i < linkses.length; i++) { var link = { source: linkses[i].source, target: linkses[i].target, label: { normal: { show: true, formatter: linkses[i].name } }, lineStyle: { normal: { color: '#12b5d0' } } } chartses.linkses.push(link) // 组装动态移动的效果数据 var linesess = [{ coord: dataMapes.get(linkses[i].source) }, { coord: dataMapes.get(linkses[i].target) }] chartses.linesDataes.push(linesess) } myChart.setOption({ notMerge: true, series: [{ data: chartses.nodeses, links: chartses.linkses, }, { data: chartses.linesDataes, }], }) }); myChart.setOption({ graphic: echarts.util.map(charts.nodes, function(item, dataIndex) { return { type: 'circle', position: myChart.convertToPixel('grid', item.value), shape: { cx: 5, cy: 5, r: 20 }, invisible: true, draggable: true, ondrag: echarts.util.curry(onPointDragging, dataIndex), onmousemove: echarts.util.curry(showTooltip, dataIndex), onmouseout: echarts.util.curry(hideTooltip, dataIndex), z: 100 }; }) }); function onPointDragging(dataIndex, dx, dy) { console.log("tempV-----"); var tempV = myChart.convertFromPixel('grid', this.position); console.log("tempV", tempV); charts.nodes[dataIndex].value = [tempV[0], tempV[1]]; // Update data myChart.setOption({ series: [{ id: 'a', data: charts.nodes }] }); } function showTooltip(dataIndex) { myChart.dispatchAction({ type: 'showTip', seriesIndex: 0, dataIndex: dataIndex }); } function hideTooltip(dataIndex) { myChart.dispatchAction({ type: 'hideTip' }); } window.addEventListener('resize', function() { myChart.resize(); myChart.setOption({ series: [{ id: 'a', data: charts.nodes }] }); });