首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用mxgraph设置自定义顶点

如何使用mxgraph设置自定义顶点
EN

Stack Overflow用户
提问于 2014-03-14 14:07:00
回答 1查看 5.9K关注 0票数 2

我们正在编写一个使用mxgraph生成图形的程序。我们的需求是“我们需要将图像显示为顶点”。我们已经尝试了许多代码,但我们无法获得图像。(图像的路径是正确的)我们可以改变节点的形状并添加颜色,但不能将图像作为顶点。我们的代码如下

代码语言:javascript
复制
         Document xmlDocument = mxDomUtils.createDocument();
         Element sourceNode = xmlDocument.createElement("Source");
         Element targetNode = xmlDocument.createElement("Target");
         Element subtargetNode = xmlDocument.createElement("Subtarget");
         mxGraph graph = new mxGraph();
         Object parent = graph.getDefaultParent();
         graph.getModel().beginUpdate();
         try{
               Object v1 = graph.insertVertex(parent, null, "source", 20, 20,80, 30,"shape=ellipse");
               Object v2 = graph.insertVertex(parent, null, "destination", 200, 20,80, 30,"shape=image;image=H:\\mywork\\mxgraph\\bin\\mypack\\bg2.jpg");
               graph.insertEdge(parent, null, "", v1,v2,"startArrow=none;endArrow=diamond;strokeWidth=4;strokeColor=#66FF00");
         }

请指导我们在上面的代码中必须纠正什么,以获得一个图像作为我的顶点。

EN

回答 1

Stack Overflow用户

发布于 2014-08-29 02:36:14

除了图像的路径,我在代码中看不到任何问题。即使你有足够的信心,也要交叉检查图像的路径。在开发者工具中打开它,检查您是否可以访问镜像。尝试直接从url访问图像。

这里的任何方法都是在mxCells上应用样式的推荐方法。

代码语言:javascript
复制
Document xmlDocument = mxDomUtils.createDocument();
     Element sourceNode = xmlDocument.createElement("Source");
     Element targetNode = xmlDocument.createElement("Target");
     Element subtargetNode = xmlDocument.createElement("Subtarget");
     mxGraph graph = new mxGraph();
     Object parent = graph.getDefaultParent();

     var style = new Object();
        style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_IMAGE;
        style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
        style[mxConstants.STYLE_IMAGE] = 'images/bg2.jpg';
        style[mxConstants.STYLE_FONTCOLOR] = '#FFFFFF';
        graph.getStylesheet().putCellStyle('image', style)

     graph.getModel().beginUpdate();
     try{
           Object v1 = graph.insertVertex(parent, null, "source", 20, 20,80, 30,"shape=ellipse");
           Object v2 = graph.insertVertex(parent, null, "destination", 200, 20,80, 30,"image");
           graph.insertEdge(parent, null, "", v1,v2,"startArrow=none;endArrow=diamond;strokeWidth=4;strokeColor=#66FF00");
     }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22397431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档