2013-07-26 37 views
3

我在Highcharts有一個餅圖。點擊餅圖的一個片段應該加載與該數據序列相關聯的URL。例如,如果有25%的切片帶有yahoo.com的網址和35%的切片到google.com,則單擊35%的切片應使用戶訪問google.comHighChart:帶有URL的甜甜圈派

這是我在系列補充說:

// ... 
point: { 
    events: { 
     click: function(e) { 
      location.href = e.point.url; 
      e.preventDefault(); 
     } 
    } 
} 
// ... 

data = [{ 
     y: 55.11, 
     color: colors[0], 
     url: 'www.google.com', 
     drilldown: { 
     name: 'MSIE versions', 
     categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'], 
     data: [10.85, 7.35, 33.06, 2.81], 
     url: 'www.google.com', 
     color: colors[0] 
     } 
}, { .......many more dataset ... 

我有一個例子JS提琴以上,但它is not working

在同一個例子中,有人建議在該系列中添加url,但這會使所有切片指向相同的URL。

本例與but also does not work相似。

+0

jsfiddle.net的鏈接必須附有代碼。 – Neal

+0

只需修復鏈接。欣賞。 –

+0

jsfiddle.net的鏈接必須附有代碼。請。 – Neal

回答

2

調試破碎實例後,問題是,url不被包括在在傳遞到圖表的數據:

// add browser data 
browserData.push({ 
    name: categories[i], 
    y: data[i].y, 
    color: data[i].color, 

    // missing this line! 
    url: data[i].url 
}); 

一旦做到這一點,這是因爲docs describe容易:

point: { 
    events: { 
     click: function(e) { 
      location.href = this.options.url; 
     } 
    } 
} 
+0

很酷的作品。非常感謝。 –