2012-03-12 140 views
0

假設左邊有一個垂直軸的共同條形圖...我想知道如何控制圖表左側和垂直軸之間的空間?這個想法是,只要軸上顯示的刻度標籤變大,軸就會向右推動以容納刻度標籤。我希望能夠指定該軸應始終顯示在圖表整個寬度的20%處,這可能嗎?JFreeChart軸位置

回答

0

條形圖通常有一個域爲CategoryAxis,因此您可以使用setLowerMargin()setUpperMargin()setCategoryMargin()進行實驗。

0

您需要設置的範圍內軸的固定軸空間: http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/plot/XYPlot.html#setFixedRangeAxisSpace:AxisSpace

假設你剛剛創建圖表的圖像:

// Get your plot from the chart object.. 
XYPlot plot = (XYPlot)chart.getPlot(); 

// Create an instance of the image so we can do some calculations 
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 

// Create an instance of the Graphics2D from your image 
Graphics2D g2 = image.createGraphics(); 

// Get the reserve space that jfree chart sets aside for the axis 
AxisSpace space = yAxis.reserveSpace(g2, plot, new Rectangle(width,height), plot.getRangeAxisEdge(), plot.getFixedRangeAxisSpace()); 

// Give that space a fixed width 
space.setLeft(fixedAxisWidth); 

// Set it in the plot 
plot.setFixedRangeAxisSpace(space); 

你也許能夠只定義AxisSpace沒有去通過所有的Graphics2D rigamarole,但這是我過去的做法。