是否可以预加载将用于<image>
的图像文件,这是一个svg元素?
使用d3,我为每个数据添加一个图像,如下所示:
var images= g.append('svg:image')
.attr('y',function(d,i){
return (yAxisScale(new Date(d.Year, 0, 1, 0)))
})
.attr('x',function(d,i){
return(xAxisScale(d.Tournament)+30)
})
.attr("width",function(d,i){
return imageScale.bandwidth()*6
})
.attr("xlink:href",function(d,i){
var filename = d.Winner;
var position = filename.indexOf("(")
if (position != -1)
filename = filename.slice(0,position)
position = filename.indexOf(":")
if (position != -1)
filename = filename.slice(position+1,filename.length)
filename=filename.replace(/\s/g,'')
return "/img/" + filename + ".jpg"
})