使用joint.js 繪製圖,joint.js繪製圖

來源:互聯網
上載者:User

使用joint.js 繪製圖,joint.js繪製圖
試了幾種在js畫graph的庫,還是joint.js合適一些,對於簡單的圖顯示很適用。具體連結:

http://www.daviddurman.com/automatic-graph-layout-with-jointjs-and-dagre.html


demo:


1.script和css下載:



http://jointjs.com/download :


<link rel="stylesheet" href="joint.css" >
<script src="joint.js" ></script>
<script src="joint.layout.DirectedGraph.js"></script>


http://www.daviddurman.com/assets/autolayout.js:


<script src="autolayout.js" ></script>


2. 範例程式碼:


<link rel="stylesheet" href="joint.css" ><script src="joint.js" ></script><script src="joint.layout.DirectedGraph.js"></script><script src="autolayout.js" ></script><textarea id="adjacency-list" rows=40 cols=100>{  'a': ['b'],  'a': ['c'],  'b': ['f'],  'c': ['e', 'd'],  'd': [],  'e': [],  'f': ['g'],  'g': []}</textarea><br><button id="btn-layout">Layout</button><div id="paper"></div><script>// Main.// -----var graph = new joint.dia.Graph;var paper = new joint.dia.Paper({    el: $('#paper'),    width: 2000,    height: 2000,    gridSize: 1,    model: graph});// Just give the viewport a little padding.V(paper.viewport).translate(20, 20);$('#btn-layout').on('click', layout);function layout() {        try {        var adjacencyList = eval('adjacencyList = ' + $('#adjacency-list').val());    } catch (e) { alert(e); }        var cells = buildGraphFromAdjacencyList(adjacencyList);    graph.resetCells(cells);    joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false });}layout();</script>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.