在Jfree图表中增加传说的大小

时间:2014-10-30 16:33:07

标签: java

如何增加显示颜色的图例键的大小。字体大小由chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));

调整

但我无法找到如何管理颜色键大小的方法。我的代码是

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 个答案:

答案 0 :(得分:1)

感谢找到的答案herehere类似的问题,我能够在我的项目中实现它。

这是我的Scala代码:

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

在Java中,这转换为:

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

结果符合我的预期:颜色键的形状和大小也相应改变。