2009-11-26 176 views
1

我試圖讓jfreechart PieChart3D隱藏標籤。我在文檔中找不到任何東西。在jfreechart/PiePlot3D餅圖上隱藏標籤

任何人都知道如何做到這一點?

<% response.setContentType("image/png"); %><%@page import="org.jfree.data.general.*"%><%@page import="org.jfree.chart.*"%><%@page import="org.jfree.chart.plot.*"%><%@page import="java.awt.Color" %><% 

      DefaultPieDataset ds = (DefaultPieDataset)session.getAttribute("usagePieOutputDataset"); 

      JFreeChart chart = ChartFactory.createPieChart3D 
      (
       null, // Title 
       ds,  // Dataset 
       false, // Show legend 
       false, // Use tooltips 
       false // Configure chart to generate URLs? 
      ); 

      chart.setBackgroundPaint(Color.WHITE); 
      chart.setBorderVisible(false); 

      PiePlot3D plot = (PiePlot3D)chart.getPlot(); 
      plot.setDepthFactor(0.0); 
      plot.setLabelOutlinePaint(Color.LIGHT_GRAY); 
      plot.setLabelFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 10)); 


      ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 150, 144); 
    %> 

http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/PiePlot3D.html

+0

你檢查我的答案?沒有評論它,也沒有被接受。這不適合你嗎?或者不是你想要的? – jitter 2009-11-29 20:43:43

回答

14

這將隱藏所有標籤:

plot.setLabelGenerator(null); //null means no labels 
1

事實上,這似乎是一個更簡單的方法,也更短。

只需自己做標籤分發(匿名實現)並假裝沒有標籤可以通過在getItemCount()中返回一個零來顯示。

plot.setLabelDistributor(new AbstractPieLabelDistributor() { 
    public int getItemCount() { return 0; } 
    public void distributeLabels(double minY,double height) {} 
}); 

舊的解決方案:

不知道如果有一個更簡單的方法,但這應該工作。應該是不言自明的。不要顯示鏈接設置一些顏色透明,不生成標籤。別的只是問。

Color transparent = new Color(0.0f,0.0f,0.0f,0.0f); 
plot.setLabelLinksVisible(Boolean.FALSE); 
plot.setLabelOutlinePaint(transparent); 
plot.setLabelBackgroundPaint(transparent); 
plot.setLabelShadowPaint(transparent); 
plot.setLabelGenerator(new PieSectionLabelGenerator(){ 
    @Override 
    public AttributedString generateAttributedSectionLabel(PieDataset dataset, Comparable key) { 
     return new AttributedString(""); 
    } 
    @Override 
    public String generateSectionLabel(PieDataset dataset, Comparable key) { 
     return ""; 
    } 
}); 
+0

那麼?這是否做你想要的? – jitter 2009-11-28 07:19:01