JFreeChart - 如何改善饼图中的标签

时间:2022-01-18 14:59:46

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

基本上我对下面的文章有一个非常类似的问题: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.

但它并没有真正的区别。最新版本中默认为无CUBIC_CURVE。 setInteriorGap确实略有改善,但它很小。另一条线没有做任何事情。

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.

真正令人不安的是生成的图表的左侧和右侧有多少空白区域。能以某种方式使用那个空间会很棒。

1 个解决方案

#1


0  

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.

生成的chartImage将包含修剪版本。确保使初始宽度和高度值大于您希望图表占据的区域的尺寸,然后将其修剪为大小。

#1


0  

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.

生成的chartImage将包含修剪版本。确保使初始宽度和高度值大于您希望图表占据的区域的尺寸,然后将其修剪为大小。