您好,登錄后才能下訂單哦!
如何在jquery中使用echarts實現可視化?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
<!DOCTYPE html> <html> <head> <meta charset="utf8"></meta> <script src="http://cdn.bootcss.com/echarts/3.2.2/echarts.js"></script> <script src="http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.min.js"></script> <script type="text/javascript"> function draw(){ var text = $("#graph-input").val(); var data = eval(text); var graph = data2Graph(data); drawGraph(graph); } function data2Graph(data) { var graph = {} var vertices = {} var links = []; for (var i = 0; i < data.length; i++) { var s = String(data[i][0]); var t = String(data[i][1]); var v = data[i][2]; vertices[s] = s; vertices[t] = t; links.push({'source' : s, 'target' : t, 'value' : v}); } var nodes = []; $.each(vertices, function(k, v) { nodes.push({'name' : v, 'value' : v}); }); graph['links'] = links; graph['data'] = nodes; return graph; } function drawGraph(graph) { var myChart = echarts.init(document.getElementById("echarts-main")); var option = { tooltip: {}, series : [ { type: 'graph', layout: 'force', symbolSize: 30, edgeSymbol: ['none', 'arrow'], data: graph.data, links: graph.links, roam: true, label: { normal: { show: true, formatter: function (e) { return e['data']['value']; } } }, edgeLabel: { normal: { show: true, position: 'middle' } }, force: { repulsion: 1000, edgeLength: 200 } } ] }; myChart.setOption(option); } $(document).ready(function(){ draw(); $("#gen-btn").on("click", function(){ draw(); }); }); </script> </head> <body> <p>在下方文本框內輸入有向圖JSON([source, target, value]):</p> <textarea id="graph-input" > [[0,1,10], [1,0,1], [1,2,5], [2,0,5]] </textarea> <p><button id="gen-btn">生成力導向圖</button></p> <div id="echarts-main" ></div> </body> </html>
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。