G6
G2
G6
F2
L7
墨者学院
关于 G6
图表示例
API 文档
使用教程
返回旧版
树图
紧凑树
系统树
生态树
脑图树
函数生成树
Newick
流图
ATM 投资关系图
表格桑基图
工作流
网图
小米关系图谱
浙江省各城市大学分布
粒子传输效果
系统增长
2017 Link Data
编辑器
简单流程图
模型流程图
脑图
网络图建模
浙江省各城市大学分布
源码
复制成功
复制失败
全屏
复制
运行
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>浙江省各城市大学分布</title> <style>::-webkit-scrollbar{display:none;}html,body{overflow:hidden;margin:0;}</style> </head> <body> <div id="mountNode"></div> <script>/*Fixing iframe window.innerHeight 0 issue in Safari*/document.body.clientHeight;</script> <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g6-3.1.1/build/g6.js"></script> <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g6-2.2.0/build/g6.js"></script> <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g6-2.2.6/build/plugins.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/jquery-3.2.1.min.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/d3-4.13.0.min.js"></script> <style> .label { fill: white; } </style> <script> $("#mountNode").css('backgroundColor', '#0F141F'); $.getJSON('https://gw.alipayobjects.com/os/antvdemo/assets/data/university.json', function(data) { var Mapper = G6.Plugins['tool.d3.mapper']; var Util = G6.Util; var _d = d3, forceSimulation = _d.forceSimulation, forceLink = _d.forceLink, forceManyBody = _d.forceManyBody, forceX = _d.forceX, forceY = _d.forceY; var nodeColorMapper = new Mapper('node', '办学层次', 'color', ['#4BA4C4', '#F0D79F', '#FF8B33']); var simulation = void 0; // 注册城市文本导引信息 G6.registerGuide('city-label', { draw: function draw(item) { var tree = item.getGraph(); var roots = tree.getRoots(); var group = item.getGraphicGroup(); roots.forEach(function(root) { var bbox = Util.getTotalBBox(root.getAllChildren().map(function(child) { return child.getBBox(); })); var model = root.getModel(); group.addShape('text', { attrs: { x: bbox.minX, y: bbox.minY - 8, text: model.name, fill: '#ccc' } }); }); } }); var tree = new G6.Tree({ container: 'mountNode', height: window.innerHeight, plugins: [nodeColorMapper], layout: function layout() { var nodes = tree.getNodes().map(function(node) { return node.getModel(); }); var edges = tree.getEdges().map(function(edge) { return Util.mix({}, edge.getModel()); }); simulation && simulation.stop(); simulation = forceSimulation(nodes).force('charge', forceManyBody()).force('link', forceLink(edges).id(function(d) { return d.id; }).distance(20).strength(1)).force('y', forceY()).on('tick', function() { tree.updateNodePosition(); }); } }); tree.node({ size: 10, style: { stroke: null } }); tree.edge({ style: function style() { return { strokeOpacity: 0.6 }; } }); tree.read(data); tree.add('guide', { shape: 'city-label' }); tree.translate(tree.getWidth() / 2, tree.getHeight() / 2); // 拖拽画布交互 var lastPoint = void 0; tree.on('canvas:mouseenter', function() { tree.css({ cursor: '-webkit-grabbing' }); }); tree.on('dragstart', function() { tree.css({ cursor: '-webkit-grabbing' }); }); tree.on('drag', function(ev) { if (lastPoint) { tree.translate(ev.domX - lastPoint.x, ev.domY - lastPoint.y); } lastPoint = { x: ev.domX, y: ev.domY }; }); tree.on('dragend', function() { lastPoint = undefined; tree.css({ cursor: '-webkit-grab' }); }); tree.on('canvas:mouseleave', function() { lastPoint = undefined; }); }); </script> </body> </html>
图表简介
展示了浙江省,各个城市,本科和专科的数量及分布情况