本文主要是介绍spark graphx 可视化:不同属性结点指定不同颜色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
普通图:
节点指定颜色的图:
方法:
自定义节点的属性如: 属性文件stylesheets,内容如下,ip节点颜色是红色
edge {
shape: cubic-curve;
fill-color: #dd1c77;
z-index: 0;
text-background-mode: rounded-box;
text-background-color: #fff7bc;
text-alignment: above;
text-padding: 2;
}
node {
fill-mode: dyn-plain;
fill-color: blue;
}
node.ip {
fill-mode: dyn-plain;
fill-color: red;
}
代码中:
val srcGraph = Graph(vertices, edges) //图的属性从自定义文档中加载 graph.setAttribute("ui.stylesheet", "url(file:./stylesheets.txt)") graph.setAttribute("ui.quality") graph.setAttribute("ui.antialias")// load the graphx vertices into GraphStream for ((id, name) <- srcGraph.vertices.collect()){val node = graph.addNode(id.toString).asInstanceOf[SingleNode]if(name != null && name=="ip")node.setAttribute("ui.class","ip") // 重点,指定节点class,这样它可以根据class寻找指定节点的属性node.addAttribute("ui.label",name) }
这篇关于spark graphx 可视化:不同属性结点指定不同颜色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!