简体   繁体   English

增加 Jfree 图表中图例的大小

[英]Increasing Size of Legends in Jfree Chart

How to Increase the Size of The Legend Keys which displays colors.如何增加显示颜色的图例键的大小。 The Font Size is adjusted by chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12)); Font Size 由chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));

but I couldnt find out the way how can I manage Size of the color Keys.但我不知道如何管理颜色键的大小。 My code is我的代码是

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);
                         }

ALso my Key Size gets reflected by small amount by plot.setSectionOutlineStroke(new BasicStroke(3));我的密钥大小也通过plot.setSectionOutlineStroke(new BasicStroke(3));得到少量反映plot.setSectionOutlineStroke(new BasicStroke(3)); .. Please Help! .. 请帮忙!

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

Thanks to the answers found here and here to similar questions, I was able to achieve it in my project.感谢在此处此处找到类似问题的答案,我能够在我的项目中实现它。

This is my Scala code:这是我的 Scala 代码:

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

In Java this translates to:在 Java 中,这转化为:

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

The result is what I expected: the shape and size of the color keys is changed accordingly.结果如我所料:颜色键的形状和大小相应地发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM