2017-10-12 87 views
0

我正嘗試使用JavaScript將mxGraph的XML圖轉換爲SVG。有了XML字符串,我需要將它解析爲SVG,以便進一步分發給html。 This post顯示我需要做什麼與solution implemented in Java。我可以將XML解析爲圖形,並且無法將圖形渲染爲SVG,似乎無法找到與mxCellRenderer.js中的drawCells()方法等效的方法。在mxGraph中將XML轉換爲SVG javascript

任何人都可以使用JavaScript(可用的mxGraph庫)將XML轉換爲SVG嗎?

回答

1

爲我工作的解決方案:

數據 - 表示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()方法的細節。

1

搜索setGraphXml函數是在mxGraph的(在editor.js內)

的graphEditor例如這將讀取XML和使得它在圖形上