根据 c3 条形图中的坐标对齐外部元素

Aligning external elements based on coordinates from a c3 bar chart

本文关键字:对齐 外部 元素 坐标 c3 条形图 根据      更新时间:2023-09-26

我正在尝试在 c3 条形图上进行叠加。我已经得到了条形图的坐标以及我希望放置一些自定义 DOM 元素的位置,但我遇到的问题是它确实与条形图正确对齐。

这是我尝试的一个jsfidd。

var label = document.createElement("p");
var text = document.createTextNode("This is 0");
label.style.top = chart.internal.height - chart.internal.x(0) + "px"
label.style.position = "relative";
label.appendChild(text);
document.getElementById("chart").appendChild(label);

http://jsfiddle.net/cjrobinson/thuwbL96/

只需要absolute定位而不是relative,之后你必须将其调整几个像素,使它们在栏中垂直居中

http://jsfiddle.net/thuwbL96/7/