2014-10-30 76 views
1

如何增加顯示顏色的圖例按鍵的大小。字體大小由chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));Jfree圖表中增加圖例大小

調整,但我無法找到方式如何管理顏色鍵的大小。我的代碼是

plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0,0.0)); 
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(
         StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT)); 
        plot.setDirection(Rotation.CLOCKWISE); 


        List keys = dataset.getKeys(); 
        int i=0; 
        for (Iterator it = keys.iterator(); it.hasNext();) { 
         Comparable key = (Comparable) it.next(); 
         plot.setSectionPaint(key,requiredcol[i]); 
         //plot.setExplodePercent(key, 0.04); 
         i++; 
        } 
        // create a Ring Chart... 
        JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); 
         chart.setPadding(new RectangleInsets(0,0,0,0)); 
         chart.setBackgroundPaint(java.awt.Color.white); 


        if(showLegend){ 
        chart.getLegend().setFrame(BlockBorder.NONE); 
        chart.getLegend().setPosition(RectangleEdge.RIGHT); 
        chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12)); 
        } 
        //chart.removeLegend(); 
        // save it to an image 
        try { 
         final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); 
         final File file1 = new File(chartDirectory + File.separator + chartFileName.toString().trim()); 
         ChartUtilities.saveChartAsPNG(file1, chart, width, height, info); 
         currentImageMap = ImageMapUtilities.getImageMap(chartFileName.toString(),info); 
         } 

也是我的主要尺寸變小量plot.setSectionOutlineStroke(new BasicStroke(3));反映..請幫助!

[1]: http://i.stack.imgur.com/bDh4Z.png 

回答

1

多虧了答案發現herehere到類似的問題,我能實現它在我的項目。

這是我的Scala代碼:

plot.getRenderer().asInstanceOf[StackedBarRenderer].setBaseLegendShape(new Rectangle(30,30)) 

在Java這樣的語句:

((AbstractRenderer) plot.getRenderer()).setBaseLegendShape(new Rectangle(30,30)); 

結果是我所期待的:顏色鍵的形狀和尺寸相應改變。