dojo图表-onmousemove在图表绘图区域中出现问题

dojo图表-onmousemove在图表绘图区域中出现问题,dojo,dojox.charting,Dojo,Dojox.charting,我试图建立一个图表,在光标下画一条垂直于X轴的线。以此为指导: 我使用下面的代码捕获 图表打印区域(不包括图表边距和标签) 通常情况下,它会按预期工作。然而,我也在图表上绘制了一个网格,每当鼠标经过网格线时,我就会得到一个“mouseout”事件。当鼠标经过带有工具提示/高亮显示操作的标记时,我也会丢失mousemove事件 问:如何在“绘图区域”上捕捉mousemove/mousemove,而不会在网格线或绘图标记上丢失它 问:有没有更好的方法来获取图表的“绘图区域”以计算偏移量?A1:在图

我试图建立一个图表,在光标下画一条垂直于X轴的线。以此为指导:

我使用下面的代码捕获 图表打印区域(不包括图表边距和标签)

通常情况下,它会按预期工作。然而,我也在图表上绘制了一个网格,每当鼠标经过网格线时,我就会得到一个“mouseout”事件。当鼠标经过带有工具提示/高亮显示操作的标记时,我也会丢失mousemove事件

问:如何在“绘图区域”上捕捉mousemove/mousemove,而不会在网格线或绘图标记上丢失它


问:有没有更好的方法来获取图表的“绘图区域”以计算偏移量?

A1:在图表上覆盖一个透明的div并使用它捕捉事件。警告-最有可能的是它会阻止事件到达标记和网格线

顺便说一句,您的示例假设您只使用SVG或VML渲染器。捕捉事件的更一般方式:

var h1 = surface.connect("onmouseout", f1);
var h2 = shape.connect("onmouseout", f2);
// ...
shape.disconnect(h2);
surface.disconnect(h1);
A2:渲染图表(并计算所有几何图形)后,可以按如下方式提取尺寸:

chart.dim; // {width, height} --- dimensions of the chart
chart.offsets; // {l, b, r, t} --- offsets from dimensions
var plotArea = {
  // in pixels relative to chart's top-left corner
  x: chart.offsets.l,
  y: chart.offsets.t,
  width:  chart.dim.width  - chart.offsets.l - chart.offsets.r,
  height: chart.dim.height - chart.offsets.t - chart.offsets.b
};
如果需要绝对页面级坐标,请使用
dojo.position()
或类似函数获取图表在页面上的位置

chart.dim; // {width, height} --- dimensions of the chart
chart.offsets; // {l, b, r, t} --- offsets from dimensions
var plotArea = {
  // in pixels relative to chart's top-left corner
  x: chart.offsets.l,
  y: chart.offsets.t,
  width:  chart.dim.width  - chart.offsets.l - chart.offsets.r,
  height: chart.dim.height - chart.offsets.t - chart.offsets.b
};