问题
I'm using JavaScript InfoVis Toolkit (http://thejit.org/) and am trying to save the Spacetree that I output into an image. The Spacetree is outputted to a canvas. This problem is really frustrating me. I have tried:
- Opening the canvas in a new window
- Opening the div where the canvas is located in a new window
- Using Canvas2Image (http://www.nihilogic.dk/labs/canvas2image/)
Here is my current Javascript method (tied to a button):
function saveImage(div_id) {
var canvas = document.getElementById("tree-canvas");
Canvas2Image.saveAsJPEG(canvas);
}
However, every time (and I mean this for all 3 options) I get my nodes but NOT the label that is assigned to the node. It's beyond frustrating!!
Has ANYONE run into this? This has to be an issue that has been run into before..
回答1:
For anyone that runs into this in the future, I got around this by:
Changing the Label type to "Native":
Label: {
type: 'Native',
color: '#000000'
},
And I also grabbed the canvas ID (HTML 5 by the way) and threw the image into a new window:
function saveImage() {
var canvas = document.getElementById("canvas");
window.open(canvas.toDataURL("image/jpeg"));
}
来源:https://stackoverflow.com/questions/11267026/jit-saving-spacetree-as-an-image