我已经把它分成tspan这样的两个DOM元素
var chart = c3.generate({
data: {
columns: [
['sample', 30, 200, 100, 400, 150, 250],
['sample2', 130, 300, 200, 500, 250, 350]
],
axes: {
sample2: 'y2'
}
},
axis: {
x: {
label: 'x-label'
},
y: {
label: 'Y Label'
},
y2: {
show: true,
label: 'Y2 Label'
}
}
});
var label = d3.select(".c3-axis-x-label");
var text = label.text();//this will give you the text
label.text("");//setting the label to be blank
label.append("tspan").text("hello ");//making a tspan and adding to x label DOM
label.append("tspan").text("World");//making a tspan and adding to x label text DOM
工作代码here
编辑
可以通过调整dx和dy属性来放置标签
label.append("tspan").text("hello ").attr("dx", -30);;//making a tspan and adding to x label DOM
label.append("tspan").text("World").attr("dy", 20).attr("dx", -25);//making a tspan and adding to x label text DOM
工作代码here
希望这会有所帮助!