繁体   English   中英

在mxGraph JavaScript中将XML转换为SVG

[英]Converting XML to SVG in mxGraph javascript

我正在尝试使用JavaScript将mxGraph的XML图转换为SVG。 具有XML字符串,我需要将其解析为SVG,以便进一步分发给html。 这篇文章确切地显示了我需要用Java实现解决方案 我可以将XML解析为图形,而不能将图形呈现为SVG,似乎无法找到与mxCellRenderer.js中的drawCells()方法等效的方法。

谁能仅使用JavaScript(可用的mxGraph库)帮助将XML转换为SVG?

对我有用的解决方案:

数据-表示mxGraphModel XML

var doc = mxUtils.parseXml(data); // parse XML into document
var graph = new Graph(container, null, null, null, null); // create Graph instance, container is an HTML element where the SVG will be exported
var outputSvg = graph.getSvg("#FFFFFF", 1, null, null, true, null, null);

最终输出是可以包含在HTML文档中的SVG对象:

document.getElementById('divForSvg').appendChild(outputSvg );

检查Graph.js及其getSvg()方法以获取详细信息。

搜索setGraphXml的graphEditor示例中的setGraphXml函数(在Editor.js中)

这将读取xml并将其呈现在图形上

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM