2017-03-22 120 views

回答

1

您可以編寫自己的功能來移動標籤。

獲取標籤元素的bbox並檢查它是否在容器內(> = 0或< =容器的寬度)。獲得bbox的一個警告 - 標籤是旋轉的,所以這意味着你得到的bbox有一個不旋轉的元素的參數 - 在你的情況下,當旋轉不會改變文本寬度 - 你可以添加一些像素抵消了這種差異。負載

function moveLabels() { 
    const ticks = this.xAxis[0].ticks; 
    const safeDistance = 10; 

    Object.keys(ticks).forEach(value => { 
    const label = ticks[value].label; 
    const bbox = label.getBBox(true); 

    if (bbox.y >= 0) { 
     if (bbox.x - safeDistance < 0) { 
     label.attr({ 
      x: label.xy.x + Math.abs(bbox.x - safeDistance) 
     }) 
     } else if (bbox.x + bbox.width + safeDistance > this.chartWidth) { 
     label.attr({ 
      x: label.xy.x - (bbox.x + bbox.width + safeDistance - this.chartWidth) 
     }); 
     } 
    } 
    }) 
} 

移動標籤/重繪事件:

chart: { 
polar: true, 
    type: 'line', 
    events: { 
     load: moveLabels, 
     redraw: moveLabels 
    } 
    }, 

例如:https://jsfiddle.net/nd5fob5d/

+0

謝謝soooooo多....它的工作 – user7674497