weixin_38807831 2019-10-20 15:13 采纳率: 0%
浏览 1972

利用echarts绘制关系图,如何根据边的权重设置边的粗细?

利用echarts Les Miserables的例子绘制了一个关系图,现在想根据边的权重设置边的粗细

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
     <script type="text/javascript" src="../js/jquery.min.js"></script>
     <script type="text/javascript" src="../js/jquery.js"></script>
        <script type="text/javascript" src="../js/echarts.min.js"></script>
          <script type="text/javascript" src="../js/dataTool.js"></script>
</head>
<body style="height: 600px; margin: 0">
<div id="container" style="height: 100%"></div>
<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var app = {};
    option = null;
    myChart.showLoading();
    $.get('../data/1.gexf', function (xml) {
        myChart.hideLoading();
        var graph = echarts.dataTool.gexf.parse(xml);
        console.log(JSON.stringify(graph));
        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 > 1
                }
            };
            node.category = node.attributes.modularity_class;
        }
        );


         option = {
            title: {
                text: 'Les Miserables',
                subtext: 'Circular layout',
                top: 'bottom',
                left: 'right'
            },
            tooltip: {},
            legend: [{
                // selectedMode: 'single',
                data: categories.map(function (a) {
                    return a.name;
                })
            }],
            animationDurationUpdate: 1500,
            animationEasingUpdate: 'quinticInOut',
            series : [
                {
                    name: 'Les Miserables',
                    type: 'graph',
                    layout: 'circular',
                    circular: {
                        rotateLabel: true
                    },
                    data: graph.nodes,
                    links: graph.links,
                    categories: categories,
                    roam: true,
                    label: {
                        normal: {
                            position: 'right',
                            formatter: '{b}'
                        }
                    },
                    edgeSymbol : [ 'none', 'arrow' ],
                    lineStyle: {
                        normal: {
                            color: 'source',
                            curveness: 0.3,

                        }
                    }
                }
            ]
        };

        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>
gexf文件的内容为
![图片说明](https://img-ask.csdn.net/upload/201910/20/1571555464_32358.png)
 运行效果为
  • 写回答

1条回答

  • huang_ftpjh 2019-10-21 11:32
    关注

    https://www.echartsjs.com/examples/zh/editor.html?c=graph-force 你是说这个?

    itemStyle 就是改变样式的 width设定宽度 把width变为数组 graph.weight

    series : [
                {
                    name: 'Les Miserables',
                    type: 'graph',
                    layout: 'force',
                    data: graph.nodes,
                    links: graph.links,
                    categories: categories,
                    roam: true,
                    itemStyle: {
                                normal: {
    
                                    lineStyle:{
                                        width:10//设置线条粗细
                                    }
                                }
                            },
                    label: {
                        normal: {
                            position: 'right'
                        }
                    },
                    force: {
                        repulsion: 100
                    }
                }
            ]
    
    <edge id="11" source="11" target="3" weight="3.0">
                    <attvalues></attvalues>
                </edge>
    

    你的width再缩小1000倍

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler