2011-08-19 66 views
3

我已經在JFreeChart中創建了一個餅圖。但是,數值沒有出現在「切片」上。我如何讓它出現在那裏?顯示JFreeChart值

+0

你是什麼意思的切片?直接在切片上,還是在切片上的標籤上?直接使用 – Jes

+0

。我也想把它應用在條形圖上(另一方面,條形圖上) – codix

回答

6

在一個PiePlot這是可能使用一個setter setSimpleLabels

假設你有你創建的圖表:

Chart chart = // your created chart 
PiePlot plot = (PiePlot) chart.getPlot(); 
plot.setSimpleLabels(true); 

如果你需要一個更簡單的看可以用作標籤陰影,輪廓和背景漆透明色:

plot.setOutlinePaint(new Color(0, 0, 0, 0)); 
plot.setLabelShadowPaint(new Color(0, 0, 0, 0)); 
plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0)); 
plot.setLabelOutlinePaint(new Color(0, 0, 0, 0)); 

編輯:要顯示切片中的值而不是圖例中的圖例:

plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}")); 

StandardPieSectionLabelGenerator也有一個數字格式化程序,如果你需要其中之一。

這應該做一個餅圖。

至於條形圖可以使用setPositiveItemLabelPositionFallback(ItemLabelPosition position)方法設置在BarRenderer的標籤位置。對於內部的標籤,你可以使用:

barRenderer.setPositiveItemLabelPositionFallback(
    new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); 

確保字體大小可以容納酒吧裏面,當你試試這個。

+0

嗯..所以顯示的值和圖例中的值是一樣的嗎? – codix

+0

您還需要設置標籤生成器,檢查編輯。 – Jes

+1

另請參閱此[答案](http://stackoverflow.com/questions/3547244/setting-label-and-value-of-the-chart/3551238#3551238)。 – trashgod