如何在 javascript 中将弹出窗口添加到动态生成的圈子

How to add popups to dynamically generated circles in javascript

我正在尝试为动态生成的圆圈创建弹出窗口(工具提示)作为在 RaphaelJS 中使用以下代码段创建的 javascript 图表的一部分:

 var p1, p2, bar_width;
 p1 = 0;
 p2 = 0 + 1;
 bar_width = c.chart_rect.width / (c.chart_data[p1][p2].length - 1) - c.series.set_gap;
 var qlc = [[]];
 var qlp = [[]];
 // Loop through series.
 for (var i = 1; i < c.chart_data[d].length; i++) {
    qlc[i] = [];
    qlp[i] = [];
    // Loop through data points.
    for (var s = 1; s < c.chart_data[d][0].length; s++) {
       qlc[i][s] = paper.circle
       (
          c.chart_rect.x + ((p2-1) * (bar_width + c.series.set_gap)) + c.series.set_gap / 2 + ((s-1) * bar_width / (c.chart_data[d][0].length - 2)),
          c.chart_rect.y + c.chart_rect.height - ((c.chart_data[d][i][s] - min) * (c.chart_rect.height / (max - min))),
          3
       ).attr({fill: "#000000", 'stroke-width': 1});
       qlp[i][s] = paper.popup(186, 215, "Hi I m a Circle...:)").attr({font: "9px sans-serif"}).hide();

       qlc[i][s].mouseover(function(){
          qlp[i][s].show();
       }).mouseout(function(){
          qlp[i][s].hide();
       });
    }
 }

但是代码在 qlp[i][s].show;qlp[i][s].hide; 行上给我一个 Uncaught TypeError: Cannot read property '8' of undefined 错误。

有人知道我哪里出错了或者我该怎么做吗?

已修复:

 var p1, p2, bar_width;
 // TODO Retrieve parameters.
 p1 = 0;
 p2 = 0 + 1;
 bar_width = c.chart_rect.width / (c.chart_data[p1][p2].length - 1) - c.series.set_gap;
 // Loop through series.
 for (var i = 1; i < c.chart_data[d].length; i++) {
    // Loop through data points.
    for (var s = 1; s < c.chart_data[d][0].length; s++) {
       paper.circle
       (
          c.chart_rect.x + ((p2-1) * (bar_width + c.series.set_gap)) + c.series.set_gap / 2 + ((s-1) * bar_width / (c.chart_data[d][0].length - 2)),
          c.chart_rect.y + c.chart_rect.height - ((c.chart_data[d][i][s] - min) * (c.chart_rect.height / (max - min))),
          3
       ).attr({fill: "#000000", 'stroke-width': 1})
       .data("x", c.chart_rect.x + ((p2-1) * (bar_width + c.series.set_gap)) + c.series.set_gap / 2 + ((s-1) * bar_width / (c.chart_data[d][0].length - 2)))
       .data("y", c.chart_rect.y + c.chart_rect.height - ((c.chart_data[d][i][s] - min) * (c.chart_rect.height / (max - min))))
       .data("t", c.chart_data[d][0][s])
       .hover(function () {
          // Show
          this.flag = paper.popup(this.data("x"), this.data("y")-5, this.data("t") || "No data found.").insertBefore(this);
       },
       function () {
          // Hide
          this.flag.animate({opacity: 0}, 300, function () {this.remove();});
       });
    }
 }