在Polymer Shadow DOM中,Dygraph的点击回调不起作用



我正在创建一个Ploymer自定义组件,并使用Dygraph创建图表。我为相同的添加了一个pointClickCallback

但是,当图表位于阴影dom内时,pointClickcallback根本不起作用。尽管如此,当我将图表放在自定义组件之外,即index.html中时,pointClickCallback运行良好。

编辑:highlightCallback在阴影dom内正常工作,而不是pointClickCallback

有人能告诉我可能出了什么问题吗。

更新

我不确定这样做是否正确,但是,请提出建议。我正在做下面这样的事情,它对我有效

var self = this; // 'this' is not the window object
self.pts = null;
var g = new Dygraph(
    this.$.div_g,
    NoisyData, {
      rollPeriod: 7,
      showRoller: true,
      errorBars: true,
      highlightCallback: function(e, x, pts, row) {
          console.log("highlightCallback --> self.pts", self.pts);
          console.log("highlightCallback", pts);
          self.pts = pts;
          console.log("highlightCallback --> self.pts", self.pts);
      },
      interactionModel : {
          'click' : function(e) {
              console.log("click", e, self.pts);
          }
      },
    }
  );

pointClickCallback不进入interactionModel,但基本上与highlightCallback处于同一级别。所以你的代码应该是这样的:

var g = new Dygraph(
    this.$.div_g,
    NoisyData, {
      rollPeriod: 7,
      showRoller: true,
      errorBars: true,
      highlightCallback: function(e, x, pts, row) {
          console.log("highlightCallback --> self.pts", self.pts);
          console.log("highlightCallback", pts);
          self.pts = pts;
          console.log("highlightCallback --> self.pts", self.pts);
      },
      pointClickCallback: function(e,pt) {
         console.log('Point clicked');
      },
      interactionModel : {
          'click' : function(e) {
              console.log("click", e, self.pts);
          }
      },
    }
  );

最新更新