简体   繁体   中英

JFreeChart - How to improve the labels in a pie chart

Basically I'm having a very similar issue to the following article: http://www.jfree.org/phpBB2/viewtopic.php?t=24713

Except that instead of differences in versions, my results for labels are much like the 3rd pie chart where I would prefer to have them like the 1st chart (more space per line - wider lines) so that they don't have to wrap to the next line so quickly. I've tried everything I can think of to increase the size of the labels, but nothing seems to be working.

My main thinking is to adjust where the label starts to get written, and through a lot of debugging the source, I was able to extend the size of the box but not the actual string. I couldn't find a way to do it without editing the source through some kind of configuration, and even then I wasn't able to adjust the text properly, only the box. And it took a good deal of effort, the code isn't in the same place for both.

Any suggestions on how to setup the pie chart so that the labels as illustrated in the article above work more like the 1st chart than the last chart would be appreciated. I did what was suggested in the post:

plot.setInteriorGap(0.02);
plot.setMaximumLabelWidth(0.20);
plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);

but it made no real difference. The default is no CUBIC_CURVE in the latest version. The setInteriorGap did have a slight improvement but it was minimal. And the other line did nothing.

What's really troubling is how much white space there is on the left and right of the generated chart. It would be great to be able to use that space somehow.

I am not sure about the first issue. However, I have some idea as to what to do about leftover whitespace.

If you are converting the chart to an image, you can try trimming the whitespace around it via the following:

BufferedImage chartImage = chart.createBufferedImage(width, height);
chartImage = chartImage.getSubImage(howMuchToTrimOnLeft, howMuchtoTrimOnTop, width - howMuchToTrimOnLeft - howMuchToTrimOnRight, height - howMuchtoTrimOnTop - howMuchToTrimOnBottom);

The resulting chartImage will contain a trimmed version. Make sure to make the initial width and height values larger than the dimensions of the area you want the chart to take up, then trim it down to size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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