你可以這樣說:在這裏
//lets create the label
var labels = svg.selectAll('text')
.data(monthlySales)
.enter()
.append('text')
.append("tspan")
.text(function(d) {
return d.stock;
}).attr({
x: function(d, i) {
var ordValue = ordinalValue(d.stock);
return xScale(ordValue);
},
y: function(d, i) {
return yScale(d.count);
},
"text-anchor": 'middle',
"font-size": 10,
"font-family": "sans-serif"
});
//lets create the count label
svg.selectAll('text').append("tspan")
.text(function(d) {
return d.count;
}).attr({
x: function(d, i) {
var ordValue = ordinalValue(d.stock);
return xScale(ordValue);
},
y: function(d, i) {
return yScale(d.count)+ 10;//to show it below the other label
},
"text-anchor": 'middle',
"font-size": 10,
"font-family": "sans-serif"
});
工作代碼(代碼中的註釋,以幫助): http://plnkr.co/edit/xDthPgsMfoGTSouVIie8?p=preview
號你需要'tspan'元素SVG。 –