我试图获取系列的起始和最后(x,y坐标),以便我可以附加到我的图表。我已经尝试查看onRendered回调,但到目前为止只能获得标签。无法得到系列开始和系列结束的实际x,y坐标(路径的开始和路径的结束)。
我的小提琴:https://jsfiddle.net/sourabhtewari/94tbbyrd/27/
这段代码给了我标签数据
function onRendered() {
console.log(this);
d3.selectAll('.c3-text').each((v) => {
console.dir(v);
});
}
尝试使用此代码段获取每个路径的第一个/最后一个点:
var sel = d3.selectAll('.c3-line');
console.log("sel:", sel);
sel.each((v, i) => {
var path = sel[0][i],
len = Math.floor( path.getTotalLength() );
console.log("#:", i);
console.log("path:", path);
console.log("nr. points:", len);
console.log("first point:", path.getPointAtLength(0));
console.log("last point:", path.getPointAtLength(len-1));
});
事实上,c3-line
是与SVG系列路径相关联的类。