2014-01-30 52 views
0

我正在使用CorePlot生成帶有橫條的條形圖(CPTXYGraph和CPTBarPlot)。如何確定/計算CorePlot中繪製Y軸刻度線的位置?

有在任何特定時間該所描繪只有10條,但對他們的標籤是任意長。由於Y軸標籤旋轉被設置爲0.5。對於最長的標籤,標籤出現在繪圖區左側和/或底部以外的剪輯問題。

我已經通過確定最長標籤的寬度(以適當的字體呈現)並旋轉適當的方式在plotAreaFrame中設置左填充,在X方向上解決了這個問題。

由於標籤的旋轉,如果在圖的底部積有很長的名字它仍然可以擴展超出圖形的底部邊緣會被切去那裏。

我知道有多高垂直旋轉的標籤,但如果我堅持正試圖確定在繪圖區域軸標籤被繪製,這樣我可以決定多少底部填充是必需的。

我不確定我是否應該試圖確定X軸標籤部分有多高,然後再細分剩餘高度以確定滴答滴答應該落在哪裏,或者如果還有其他更好的方法可以解決問題。

回答

0

有一些方法,讓你一點從情節轉換空間座標系到視圖座標系。我已經結束了類似下面的代碼解決這個問題:

// Tell the graph to lay itself out if it needs to. 
[self.graph layoutIfNeeded]; 

// Create a point that represents 0,1 as plotted on the graph. 
NSDecimal plotPoint[2]; 
plotPoint[CPTCoordinateX] = CPTDecimalFromInt (0); 
plotPoint[CPTCoordinateY] = CPTDecimalFromInt (1); 

// Convert that point from the plot coordinate system to the view coordinate system 
CGPoint point = [self.graph.defaultPlotSpace plotAreaViewPointForPlotPoint: plotPoint]; 

// If the difference between the height of the rotated label and the position that it 
// will be plotted at is at least the bottom padding, then the height is too large, 
// so fix the padding. 
if (labelHeight - point.y >= self.graph.plotAreaFrame.paddingBottom) 
    [self.graph.plotAreaFrame setPaddingBottom: (labelHeight - point.y)]; 

我的圖表有一個默認的底部填充已經被設置爲最低,讓這個代碼撞它,如果沒有足夠的了。

0

該標籤可從最近的刻度標記的一端由labelOffset偏移。刻度線末端的位置取決於tickDirection,tickLabelDirectionmajorTickLength

+0

看起來像它告訴我水平距離Y軸線多遠,標籤將被繪製。有沒有辦法確定它與繪圖區域底部的垂直偏移? – OdatNurd

相關問題