2013-04-11 154 views
3

我需要使用Highcharts(v3.0.1)的圖例標題,但是邊框不會渲染到標題的長度。這是一個錯誤嗎?我不能使用width,因爲我使用的是layout: horizontalHighcharts傳說標題邊框不是全寬

添加多於1個系列時沒有問題,但如果您只有1個,則圖例佈局(視覺上)中會出現錯誤。

例子:http://jsfiddle.net/3cSVr/1/

$(function() { 
    var chart; 

    $(document).ready(function() { 

     chart = new Highcharts.Chart({ 

      chart: { 
       renderTo: 'container', 
       type: 'line', 
      }, 
      plotOptions: {},     
      title: { 
       text: 'Monthly Average Temperature', 
       x: -20 //center 
      }, 
      subtitle: { 
       text: 'Source: WorldClimate.com', 
       x: -20 
      }, 
      xAxis: { 
       categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
      }, 
      yAxis: { 
       title: { 
        text: 'Temperature (°C)' 
       }, 
       plotLines: [{ 
        value: 0, 
        width: 1, 
        color: '#808080' 
       }] 
      }, 
      tooltip: { 
       formatter: function() { 
         return '<b>'+ this.series.name +'</b><br/>'+ 
         this.x +': '+ this.y +'°C'; 
       } 
      },  
      legend: { 
       title: { 
        text: 'WorldClimate.com', 
        style: { 
         fontWeight: 'bold' 
        } 
       }, 
       borderWidth: 2 
      },    
      series: [{ 
       name: 'Tokyo', 
       data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]     
      } 
        //Add more series; 
      ] 
     }); 
    });  
}); 

感謝您的幫助。

回答

0

最近我有同樣的問題,我解決了它這種方式:

function updateLegendBox(chart){ 
    //number of series 
    if(chart.series.length == 1){ 
     var title = $("g.highcharts-legend-title tspan")[0]; 
     var len = title.textContent.length * 8; 
     var box = $("g.highcharts-legend rect")[0]; 
     box.setAttribute('width', len) 
    } 
} 

var chart = new Highcharts.Chart({...}); 
updateLegendBox(chart); 

我希望這將是有益的

+0

Maxi Baez,感謝您的幫助,但是如果我將wid我的傳說中的第一個變成垂直的,我需要保持水平。 – user2272228