Echarts 关系图 添加点击事件

/*
实现的效果是:在关系图上加点击事件,点击某个点,得到改点代表的内容,并且实现一个跳转效果。

关键代码已用红色标出
*/


<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="ECharts"> <meta name="author" content="kener.linfeng@gmail.com"> <title>新闻关系</title> <link rel="shortcut icon" href="../asset/ico/favicon.png"> <link href="../asset/css/font-awesome.min.css" rel="stylesheet"> <link href="../asset/css/bootstrap.css" rel="stylesheet"> <link href="../asset/css/carousel.css" rel="stylesheet"> <link href="../asset/css/echartsHome.css" rel="stylesheet"> <script src="./www/js/echarts.js"></script> <script src="../asset/js/codemirror.js"></script> <script src="../asset/js/javascript.js"></script> <link href="../asset/css/codemirror.css" rel="stylesheet"> <link href="../asset/css/monokai.css" rel="stylesheet"> </head> <body> <!-- Fixed navbar --> <div class="container-fluid"> <div class="row-fluid example"> <div id="sidebar-code" class="col-md-4" > <div class="well sidebar-nav"> <div class="nav-header"><a href="#" οnclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div> <textarea id="code" name="code"> option = { title : { text: '', subtext: '', x:'right', y:'bottom' }, tooltip : { trigger: 'item', formatter: '{a} : {b}' }, toolbox: { show : true, feature : { restore : {show: true}, magicType: {show: true, type: ['force', 'chord']}, saveAsImage : {show: true} } }, legend: { x: 'left', data:['家人','朋友'] }, series : [ { type:'force', name : "人物关系", ribbonType: false, clickable :true, categories : [ { name: '人物' }, { name: '家人' }, { name:'朋友' } ], itemStyle: { normal: { label: { show: true, textStyle: { color: '#333' } }, nodeStyle : { brushType : 'both', borderColor : 'rgba(255,215,0,0.4)', borderWidth : 1 }, linkStyle: { type: 'curve' } }, emphasis: { label: { show: false // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE }, nodeStyle : { //r: 30 }, linkStyle : {} } }, useWorker: false, minRadius : 15, maxRadius : 25, gravity: 0.1, scaling: 1.1, roam: 'move', nodes:[ {category:1, name: '李四',value : 2}, {category:1, name: '张三', value : 4,onclick:function focus(param){ }}, ], links : [ {source : '李四', target : '张三', weight : 10, name: ''}, ] } ] }; var ecConfig = require('echarts/config'); function focus(param) { if (typeof param.seriesIndex == 'undefined') { return; } if (param.type == 'click') { window.location.href=''; } } myChart.on(ecConfig.EVENT.CLICK, focus) myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () { console.log(myChart.chart.force.getPosition()); }); </textarea> </div><!--/.well --> </div><!--/span--> <div id="graphic" class="col-md-8"> <div id="main" class="main"></div> <div> <button type="button" class="btn btn-sm btn-success" οnclick="refresh(true)">刷 新</button> <select id="theme-select"></select> <span id='wrong-message' style="color:red"></span> </div> </div><!--/span--> </div><!--/row--> </div><!--/.fluid-container--> <!-- Le javascript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="../asset/js/jquery.min.js"></script> <script type="text/javascript" src="../asset/js/echartsHome.js"></script> <script src="../asset/js/bootstrap.min.js"></script> <script src="../asset/js/echartsExample.js"></script> </body> </html>

  

转载于:https://www.cnblogs.com/lyr2015/p/7017962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值