2014-10-30 48 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)); 

结果是我所期待的:颜色键的形状和尺寸相应改变。