如何设置x和y轴的交点
问题描述:
我使用d3.js作为散点图,我想绘制x和y轴,使它们相交点(100,75)。如何做到这一点?
我使用
I am using d3.js for scatter plot,I want to plot x and y axis such that they intersect at point(100,75).how to do this? I am using
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + (padding+223) + ")")
.call(xAxis2);
//Create Y2 axis
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + (padding+200) + ",0)")
.call(yAxis2);
但是这不会根据比例改变,我已经使用了比例变量。
如果您需要更多信息,请让我知道。
But this will not change according to the scale,and I have used variable for scale. Please let me know if you need more information.
答
,您可以使用轴的比例确定,即
You would need to offset the axes by the respective amount, which you can determine using the scales of the axes, i.e.
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + yScale(75) + ")")
.call(xAxis2);
,类似地对于y轴。您可能需要稍微调整偏移量才能考虑其他偏移量,标签等。
and similarly for the y axis. You may have to tweak the offset slightly to account for other offsets, labels etc.