echarts统计图表与工具关系可视化

     制作这份图的前提之下,先做了一份gexf格式的数据,这种格式数据结构就是网状节点,结构中主要分成两部分,一部分是节点(node),包括id,节点位置、颜色渲染、节点种类、节点属性、节点值,另外一部分是edge,包括id,source(源点)、target(目标点)和value(值)。




然后制作图格式数据之后,就可以使用Echarts.JS中进行配置项设置,使用的是setoptions—series—type:”graph”。

访问地址:http://106.14.147.72/Graphtest/graphnetwork.html

效果图:


源码如下

<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="JS/echarts.js"></script>
    <script type="text/javascript" src="JS/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="JS/dataTool.js"></script>
</head>
<body style="height: 100%; margin: 0">
<div id="title" style="height: 6%">
<h2 style="text-align:center">统计图表与工具</h2>
</div>
<div id="container"  style="height: 94%;"></div>
<script>
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var app = {};
    option = null;
    myChart.showLoading();
    $.get('Data/les-miserables.gexf', function (xml) {
        myChart.hideLoading();
        var graph =echarts.dataTool.gexf.parse(xml);
        var categories = [];
        categories[0] = { name: '图表分类' };
        categories[1] = { name: '图表类型' };
	    categories[2] = { name: '图表工具' };
        graph.nodes.forEach(function (node) {
            var attr=[]
            attr.push(node.attributes.text.toString()),
            node.value =attr,
			node.symbol='circle',
            node.label = {
                normal: {
                    show:true,
					position:'inside',
					 textStyle: {
                            'color': 'white',
                            'fontSize': 12,
							'fontWeight':'bold'
                        }
                }
            };
            node.category = node.attributes.modularity_class;
        });
        option = {
            tooltip: {
			show:true,
			},
            legend: [{
                // selectedMode: 'single',
                data: categories.map(function (a) {
                    return a.name;
                })
            }],
			//backgroundColor:'#F5F5DC',
            animationDuration: 1500,
            animationEasingUpdate: 'quinticInOut',
            series : [
                {
                    name: '',
                    type: 'graph',
                    layout: 'none',
                    data: graph.nodes,
                    links: graph.links,
					left:150,
					top:70,
					focusNodeAdjacency: true,
                    categories: categories,
					edgeSymbol: ['circle', 'arrow'],
					edgeSymbolSize: [4, 10],
					label: {
                        normal: {
                            position: 'right',
                            formatter: '{b}'
                        }
                    },
                    lineStyle: {
                        normal: {
						width:2,
						opacity:0.8,
                    color: '#38f',
                    curveness: Math.random() * 0.3 // 线的弯曲度 0-1之间 越大则歪曲度更大
                        }
                    }
                }
            ]
        };

        myChart.setOption(option);
    }, 'xml');
   if (option && typeof option === "object") {
        var startTime = +new Date();
        myChart.setOption(option, true);
        var endTime = +new Date();
        var updateTime = endTime - startTime;
        console.log("Time used:", updateTime);
    }
	
</script>
</body>
</html>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值