Javascript D3Cloud-将图像base64编码发送到服务器
也许这是一个愚蠢的问题,但我没能自己弄明白,我还没有找到合适的答案 我正在构建一个网站,需要根据用户输入动态创建标记云,并将生成的图像存储在Web服务器上 我正在使用d3cloud库()创建tagclouds 这是div,其中将显示tagcloud和绘图功能:Javascript D3Cloud-将图像base64编码发送到服务器,javascript,svg,base64,tag-cloud,word-cloud,Javascript,Svg,Base64,Tag Cloud,Word Cloud,也许这是一个愚蠢的问题,但我没能自己弄明白,我还没有找到合适的答案 我正在构建一个网站,需要根据用户输入动态创建标记云,并将生成的图像存储在Web服务器上 我正在使用d3cloud库()创建tagclouds 这是div,其中将显示tagcloud和绘图功能: <div id="cloud"></div> ... function draw(words) { d3.select("#cloud") .
<div id="cloud"></div>
...
function draw(words) {
d3.select("#cloud")
.append("svg")
.attr("width", 850)
.attr("height", 350)
.attr("class", "wordcloud")
.append("g")
// without the transform, words words would get cutoff to the left and top, they would
// appear outside of the SVG area
.attr("transform", "translate(320,200)")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) {
return d.size + "px";
})
.style("fill", function(d, i) {
return color(i);
})
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) {
return d.text;
});
...
函数图(字){
d3.选择(“云”)
.append(“svg”)
.attr(“宽度”,850)
.attr(“高度”,350)
.attr(“类”、“字云”)
.附加(“g”)
//如果不进行转换,单词将从左上方截断,它们将
//显示在SVG区域之外
.attr(“转换”、“翻译(320200)”)
.selectAll(“文本”)
.数据(字)
.enter().append(“文本”)
.style(“字体大小”,函数(d){
返回d.size+“px”;
})
.style(“填充”,函数(d,i){
返回颜色(i);
})
.attr(“转换”,函数(d){
返回“translate(“+[d.x,d.y]+”)rotate(“+d.rotate+”)”;
})
.text(功能(d){
返回d.text;
});
是否可以使用base64对生成的标记云图像进行编码并将其存储到变量中?我需要在稍后的步骤中将其发送到服务器。我知道发送部分是如何工作的,我的问题只是获取编码的图像数据
关于你能用
canvas
代替div
吗?看这个-->XMLSerializer将DOM转换成字符串,然后用base64转换那个字符串,你就完成了。你能用canvas
代替div
吗?看这个-->XMLSerializer将DOM转换成字符串,然后用base64转换那个字符串,你就完成了“好了。