2015-11-03 77 views
0

我試圖創建彈出窗口(提示)動態生成的圈子中RaphaelJS用下面的代碼段創建一個JavaScript圖表的一部分:如何添加彈出窗口動態生成的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錯誤。

有人知道我要去哪裏錯或我該怎麼做?

回答

0

修正了這一點:

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();}); 
     }); 
    } 
} 
相關問題