我正在编写d3.js用于生成许多图表和图形..但是当没有数据时,我只是附加svg文本并写入"无数据显示"并分配一些属性,如xy dy等..类似字体大小但是除了字体大小,每件事都有效.
为什么?这是我的代码
var svg = d3.select(selector).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
if (!data.IssueTrendsDAO.issueTrendList) {
svg.append("text")
.attr("font-size","34px")
.attr("y", 79)
.attr("x", 40)
.attr("dy", ".47em")
.style("text-anchor", "start")
.style("fill", "#004669")
.style("font-weight", "bold")
.text("No data to display");
}
Run Code Online (Sandbox Code Playgroud)
小智 86
如果您将font-size指定为样式而不是属性,我认为您会发现它有效.
.style("font-size", "34px")
Run Code Online (Sandbox Code Playgroud)
(更好的是,分配一个id或class属性并在CSS中设置所有样式)