Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Canvas 有没有办法将画布元素作为图像添加到svg_Canvas_Svg_D3.js - Fatal编程技术网

Canvas 有没有办法将画布元素作为图像添加到svg

Canvas 有没有办法将画布元素作为图像添加到svg,canvas,svg,d3.js,Canvas,Svg,D3.js,我这里有一个JSFIDLE: 我要做的是添加我刚才在svg板上绘制的临时画布元素。 可能吗 我现在想做的是: svg.append("image") .attr("xlink:href", temp_canvas) .attr("x", 0) .attr("y", 0); 谢谢在画布元素上使用toDataURL()生成数据uri 还要为d3 svg指定宽度和高度属性: svg.append("image") .attr("xlink:href", temp_c

我这里有一个JSFIDLE:

我要做的是添加我刚才在svg板上绘制的临时画布元素。 可能吗

我现在想做的是:

svg.append("image")
    .attr("xlink:href", temp_canvas)
    .attr("x", 0)
    .attr("y", 0);
谢谢

在画布元素上使用
toDataURL()
生成
数据uri

还要为d3 svg指定宽度和高度属性:

svg.append("image")
    .attr("xlink:href", temp_canvas.toDataURL())
    .attr("x", 0)
    .attr("y", 0)
    .attr("width", 300)
    .attr("height", 300);

请注意,如果画布上的内容来自页面以外的其他来源(即绘制到画布的图像来自不同的域),则此操作不起作用