2016-05-16 50 views
2

我在Highcharts產生的氣泡圖表繪圖的底部如下:Highcharts - BubbleChart中 - 添加填充到頂部和

jsFiddle

正如你可以看到「氣泡」爲數據「0」和數據'7'被切斷。

無論如何在頂部和底部添加填充以考慮此問題?

我知道軸的範圍擴展到-1 - > 8將整理了這一點,但我寧願沒有這樣做的

下面的代碼:

$(function() { 

    var data = [{ x: 0, y: 1, z: 1, dataSeries: 'data #1', dataPerc: '1.2' }, 
       { x: 1, y: 2, z: 2, dataSeries: 'data #2', dataPerc: '2.2' }, 
       { x: 2, y: 0, z: 0, dataSeries: 'data #3', dataPerc: '19.2' }, 
       { x: 3, y: 7, z: 7, dataSeries: 'data #4', dataPerc: '12.0' }, 
       { x: 4, y: 5, z: 5, dataSeries: 'data #5', dataPerc: '24' }, 
       { x: 5, y: 4, z: 4, dataSeries: 'data #6', dataPerc: '12' }, 
       { x: 6, y: 3, z: 3, dataSeries: 'data #7', dataPerc: '15.3' }, 
       { x: 7, y: 3, z: 3, dataSeries: 'data #8', dataPerc: '1.2' }];   

    $('#container').highcharts({ 

     chart: { 
      type: 'bubble', 
      plotBorderWidth: 1, 
      zoomType: 'xy' 
     }, 
      credits: false, 

     legend: { 
      enabled: false 
     }, 

     title: { 
      text: '' 
     }, 

     xAxis: { 
      gridLineWidth: 1, 
      title: { 
       text: '' 
      }, 
      categories: ['data #1', 'data #2', 'data #3', 'data #4', 'data #5', 'data #6', 'data#7', 'data #8'] 
     }, 

     yAxis: { 
      startOnTick: true, 
      min: 0, 
      max: 7, 
      title: { 
       text: 'Score' 
      }, 
      labels: { 
       format: '{value}' 
      }, 
      maxPadding: 0.2 
     }, 

     tooltip: { 
      useHTML: true, 
      headerFormat: '<table>', 
      pointFormat: '<tr><th colspan="2"><h3>{point.dataSeries}</h3></th></tr>' + 
       '<tr><th>Score:</th><td>{point.y}</td></tr>' + 
       '<tr><th>Percentage:</th><td>{point.dataPerc}%</td></tr>', 
      footerFormat: '</table>', 
      followPointer: true 
     }, 

     plotOptions: { 
      series: { 
       dataLabels: { 
        enabled: true, 
        format: '{point.name}' 
       } 
      } 
     }, 
     series: [{ data: data }] 
    }); 
}); 

回答

2

我碰到在Google搜索中回答這個問題:http://www.java2s.com/Tutorials/highcharts/Example/Axis_Label/Hide_axis_first_label.htm

此代碼示例展示了屬性稱爲showFirstLabelshowLastLabel,你既可以在xAxisyAxis使用。這些應該通過增加yAxis(到-1到8)的範圍來增加泡泡的額外空間,但是不會顯示那些額外的標籤,如您在問題中所要求的那樣,完成您想要的任務。

這裏就是我在你的圖表選項應用於他們...

yAxis: { 
     startOnTick: true, 
     min: -1, 
     max: 8, 
     showFirstLabel: false, 
     showLastLabel: false, 
     title: { 
      text: 'Score' 
     }, 
     labels: { 
      format: '{value}' 
     }, 
     maxPadding: 0.2 
    }, 

...這裏是結果:

enter image description here

您可以查看的更新版本的這裏撥弄:http://jsfiddle.net/brightmatrix/svcuLgso/7/

我希望這有助於!

+0

天才 - 謝謝:) –