[英]JfreeChart fix the Pie Chart Radius
我正在使用jFreeChart並繪制帶有圖例的餅圖。 餅圖的半徑因圖例而異,所以我想固定餅圖的大小(圖區域)
RingPlot plot = new RingPlot(dataset);
StringBuffer chartFileName = new StringBuffer(Integer.toString(generatedCharts)).append(Long.toString(System.currentTimeMillis())).append(".png");
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));
TextTitle t = chart.getTitle();
t.setHorizontalAlignment(org.jfree.ui.HorizontalAlignment.LEFT);
t.setPaint(new Color(240, 240, 240));
t.setFont(new Font("Arial", Font.BOLD, 26));
plot.setBackgroundPaint(null);
plot.setOutlineVisible(false);
plot.setLabelGenerator(null);
plot.setSectionDepth(0.35);
plot.setSectionOutlinesVisible(false);
plot.setSimpleLabels(true);
plot.setShadowPaint(null);
plot.setOuterSeparatorExtension(0);
plot.setInnerSeparatorExtension(0);
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}",new DecimalFormat("#,##0"), new DecimalFormat("0.000%")));
plot.setLabelBackgroundPaint(null);
plot.setLabelOutlinePaint(null);
Font font=new Font("",0,16);
plot.setLabelFont(font);
chart.getLegend().setFrame(BlockBorder.NONE);
chart.getLegend().setPosition(RectangleEdge.BOTTOM);
chart.setBackgroundPaint(java.awt.Color.white);
chart.setPadding(new RectangleInsets(4, 8, 2, 2));
我能夠將您的代碼添加到ApplicationFrame
,我得到了:
我確實有一些發現:
JFreeChart chart = ChartFactory.createRingChart(...);
。 setInteriorGap()
, setLabelGap()
, setLabelLinkMargin()
和/或setMaximumLabelWidth()
。 如果只想更改圖表的半徑,則將以下代碼添加到您的代碼中:
public static void setPieRadius(JFreeChart chart, double radius) { if (chart != null) { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; double ig = 1.0 - radius; if (ig > PiePlot.MAX_INTERIOR_GAP) { ig = PiePlot.MAX_INTERIOR_GAP; } piePlot.setInteriorGap(ig); } } }
我仍然不確定您的問題是什么。 我建議您獲得更多的JFreeChart
餅圖示例,並在JFreeChart論壇中發布特定的問題描述(如果需要,也可以在此處)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.