根据C3 文档,legend.inset.postition
仅支持top-left
, top-right
,bottom-left
和bottom-right
位置。我想让我的传奇定位在top-center
.
这是创建情节的JS:
var chart = c3.generate({
data: {
columns: [
['data1', 100, 200, 50, 300, 200, 50, 250, 100, 200, 400, 50],
['data2', 400, 500, 250, null, 300, 50, 200, 450, 300, 300, 100]
],
},
legend: {
position: 'inset',
inset: {
anchor: 'top-left', // how do I implement 'top-center'?
x: 40,
y: 2,
step: 1
}
}
});
在绘制图表后,我试图通过计算元素的当前位置来重新定位元素。但是,所有 SVG 元素似乎都没有启用这种自省的属性:
var legend = d3.select(".c3-legend-background");
console.log("style[width]: " + legend.style("width")); // style[width]: auto
console.log("attr[x]: " + legend.attr("x")); // attr[x]: null
console.log("attr[y]: " + legend.attr("y")); // attr[y]: null