2013-02-12 85 views
2

我想在圖表上覆蓋自定義圖層(例如評論,作者)。閱讀API似乎已經an object for the purposeHighcharts:在圖表上疊加標籤

一個HTML標籤,可以定位在圖表區域的任何位置。

我嘗試在示例圖表之一上使用它,但它沒有效果(見下文),儘管解釋器不會發出任何錯誤。我做錯了什麼或者是否應該用其他方式創建這種類型的標籤?

謝謝。

chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'pie-container', 
      plotBackgroundColor: null, 
      plotBorderWidth: null, 
      plotShadow: false 
     }, 
     title: { 
      text: 'Browser market shares at a specific website, 2010' 
     }, 
     tooltip: { 
      pointFormat: '{series.name}: <b>{point.percentage}%', 
      percentageDecimals: 1 
     }, 
     plotOptions: { 
      pie: { 
       allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: true, 
        color: '#FFFFFF', 
        connectorColor: '#FFFFFF', 
        formatter: function() { 
         return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; 
        } 
       } 
      } 
     }, 
     series: [{ 
      type: 'pie', 
      name: 'Browser share', 
      data: [ 
       ['Firefox', 45.0], 
       ['IE',  26.8], 
       { 
        name: 'Chrome', 
        y: 12.8, 
        sliced: true, 
        selected: true 
       }, 
       ['Safari', 8.5], 
       ['Opera',  6.2], 
       ['Others', 0.7] 
      ] 
     }], 
     labels: [ 
      {html: "<b>This is a label!</b>", 
      style: { 
       left: '100px', 
       top: '100px', 
       width: '50px'}}], 
     }); 
    }); 
}); 

回答

3

labels應該是一個對象。
然後你必須添加每個標籤作爲items的元素。

labels: { 
    items: [{ 
     html: "<b>This is a label!</b>", 
     style: { 
      left: '100px', 
      top: '100px', 
      width: '50px' 
     } 
    }] 
} 

Demo

+0

感謝里卡多,做它。 – 2013-02-14 20:33:57

+0

@LuísdeSousa不客氣。 – 2013-02-14 20:51:36