2012-02-08 45 views
2

我使用高分散散點圖。我想給點選擇一個點發光效果。所以我使用chart.renderer.rect()方法創建一個SVG元素並將其添加到選定點後面。但我沒有得到所選點的xy位置。請幫幫我。Highcharts javascript

下面是我正在使用的代碼。

chart.renderer.rect(1, 1, 30, 30, 5) 
.attr({ 
     'stroke-width': 2, 
     stroke: 'red', 
     fill: 'yellow', 
     zIndex: 3, 
     translateX: 220, 
     translateY: 265 
}) 
.add(); 

在此先感謝..!

+0

請出示你的代碼的其餘部分。 – Blowsie 2012-02-08 11:08:47

回答

1

變換不attr對象部分看這裏...... http://www.highcharts.com/ref/#element

attr Object hash : Element Since 2.0 
Apply attributes to the SVG/VML elements. These attributes for the most parts correspond to SVG, but some are specific to Highcharts, like zIndex and rotation for text. 

Most important available attributes: 

d 
end 
fill 
height 
r 
rotation 
start 
stroke 
stroke-width 
style 
text 
translateX 
translateY 
visibility 
width 
x 
y 
zIndex 
+0

我試着用translateX,translateY。它顯示矩形。但是這個職位並不在適當的地方。 point.x和point.y是圖形點。但我需要一個容器中的某個點的xy位置 – user1196935 2012-02-08 11:39:10

+0

我建議您將代碼放在jsfiddle上,以便人們可以看到其餘的代碼並嘗試修復它 – Blowsie 2012-02-08 12:28:38

3

請看下面的例子。 http://jsfiddle.net/cfKzS/7/ 如果你想要圖表的x和y位置,你可以訪問爲this.x和this.y. 或者,如果你想以像素爲單位的位置,你可以使用這樣的事情:

plotOptions: { 
    series: { 
     allowPointSelect: true, 
     point: { 
      events: { 
       select: function(e) { 
        $report.html('chart x position: ' + e.target.plotX + '<br>' + 'chart y position: ' + e.target.plotY); 
       } 
      } 
     } 
    } 
}