Echarts关系图

该博客通过一个示例展示了如何使用Echarts库创建关系图。内容包括加载Echarts和相关依赖库,从外部数据源获取数据,解析数据并设置图表选项,如标题、图例、节点样式和链接样式,最后展示图表。博客使用了Les Miserables的数据集来呈现图的布局和交互效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html style="height: 100%">
   <head>
       <meta charset="utf-8">
       <title>Echarts关系图解析</title>
   </head>
   <body style="height: 100%; margin: 0">
       <!-- 为 ECharts 准备一个具备大小(宽高)的 容器 -->
       <div id="container" style="height:900px;"></div>
       <script type="text/javascript" src="js/echarts.js"></script>
       <script type="text/javascript" src="js/jquery.js"></script>
       <script type="text/javascript" src="js/dataTool.js"></script>

       <script type="text/javascript">
           // 基于准备好的容器(这里的容器是id为chart1的div),初始化echarts实例
                var dom = document.getElementById("container");
                var myChart = echarts.init(dom);

           myChart.showLoading();
           $.get('data/les-miserables2.gexf', function (xml) {
               myChart.hideLoading();

               var graph = echarts.dataTool.gexf.parse(xml);
               var categories = [];
               for (var i = 0; i < 9; i++) {
                   categories[i] = {
                       name: '类目' + i
                   };
               }
               graph.nodes.forEach(function (node) {
                   node.itemStyle = null;
                   node.value = node.symbolSize;
                   node.symbolSize /= 1.5;
                   node.label = {
                       normal: {
                           show: node.symbolSize > 30
                       }
                   };
                   node.category = node.attributes.modularity_class;
               });
               option = {
                   title: {
                       text: 'Les Miserables',
                       subtext: 'Default layout',
                       top: 'bottom',
                       left: 'right'
                   },
                   tooltip: {},
                   legend: [{
                       // selectedMode: 'single',
                       data: categories.map(function (a) {
                           return a.name;
                       })
                   }],
                   animationDuration: 1500,
                   animationEasingUpdate: 'quinticInOut',
                   series : [
                       {
                           name: 'Les Miserables',
                           type: 'graph',
                           layout: 'none',
                           data: graph.nodes,
                           links: graph.links,
                           categories: categories,
                           roam: true,
                           focusNodeAdjacency: true,
                           itemStyle: {
                               normal: {
                                   borderColor: '#fff',
                                   borderWidth: 1,
                                   shadowBlur: 10,
                                   shadowColor: 'rgba(0, 0, 0, 0.3)'
                               }
                           },
                           label: {
                               position: 'right',
                               formatter: '{b}'
                           },
                           lineStyle: {
                               color: 'source',
                               curveness: 0.3
                           },
                           emphasis: {
                               lineStyle: {
                                   width: 10
                               }
                           }
                       }
                   ]
               };

               myChart.setOption(option);
           }, 'xml');
            </script>
   </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

带刀走江湖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值