捕获XAxis值NVD3堆积面积图 [英] Capture XAxis value NVD3 Stacked Area Chart
问题描述
我在NVD3中的StackedAreaChart捕获一些数据时遇到问题。
I'm having trouble with capturing some data on the StackedAreaChart in NVD3.
我可以使用这个答案成功拦截点击事件:
NVD3堆叠区域图
I'm able to successfully intercept the click event using this answer: NVD3 Stacked Area Chart
但是,我需要更进一步。现在我拦截了这个事件,我收回了一个像这样的对象:
However, I need to go one step deeper. Now that I've intercepted the event, I'm getting back an object that looks like this:
{
point: {key:"A Place", values:[], seriesIndex: 1},
pos: [479, 283],
series: "A Place",
seriesIndex: 1
}
对象的pos数组看起来最有希望 - 数组中的第一个元素显然第二个元素的x坐标是y坐标。
The object's pos array looks the most promising- the first element in the array is obviously the x coordinate with the second element being the y coordinate.
我试图将此数字转换为生成x轴值的相同函数,以便给出x轴上的数据点寻找。但是,我没有运气,我的办公桌开始有一个弓,它已经反复砰我的头。
I'm trying to pipe this number into the same function that generates the x-axis values in order to give me the data point on the x-axis I'm looking for. However, I haven't had any luck and my desk is starting to have a bow to it where I've been repeatedly slamming my head.
任何人都有任何洞察力,如何我可以基本上向后走和管道坐标我回到图表功能在d3获得x值我这样deisre?
Anyone have any insight on how I can essentially walk backwards and pipe the coordinates I'm getting back into the chart functions available in d3 to get the x-value I so deisre?
推荐答案
要将坐标从屏幕坐标转换回输入,您需要首先使用转换它的比例。
To convert a coordinate back from screen coordinates into the input, you need to use the scale that transformed it in the first place.
您可以通过轴组件访问缩放,然后可以在坐标上调用 invert
。
You can access the scale through the axis component, and then can call invert
on the coordinate.
下面是一个例子:
var xDataPoint = chart.xAxis.scale().invert(xScreenCoord);
这篇关于捕获XAxis值NVD3堆积面积图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!