Jfreechart 中条形的宽度
有没有办法调整条形图中条形的宽度?
我使用以下代码创建图表。
final JFreeChart chart = ChartFactory.createBarChart("Report", // chart title
"Date", // domain axis label
"Number", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
Is there a way to adjust the width of the bars in a Barchart?
I create my chart with the following code.
final JFreeChart chart = ChartFactory.createBarChart("Report", // chart title
"Date", // domain axis label
"Number", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以设置条形的最大宽度。如果您有一个宽图表,但有时只有一两个数据点,并且您不希望一个大的粗条占据整个区域,那么这非常有用。
You can also set the maximum width of a bar. This is useful if you have a wide chart but occasionally there are only one or two data points and you don't want a single big fat bar taking up the whole area.
您无法直接指定条形的宽度,但可以更改一些影响宽度的属性。您应该查看 lowerMargin、upperMargin 和 categoryMargin 属性由 CategoryAxis 或 BarRenderer 中的 itemMargin 属性定义。
例如:
setItemMargin(double%)
中指定的 double 是类别轴总长度的百分比,该轴将用于同一类别内条形图之间的间距(默认值为 0.2 或20%)。该值越小,条形越大。You can't directly specify the width of the bars, but there's a few attributes that can be changed which affect the width. You should take a look at the lowerMargin, upperMargin and categoryMargin attributes defined by the CategoryAxis or the itemMargin attribute in the BarRenderer.
For example:
The double specified in
setItemMargin(double percent)
is the percentage of the overall length of the category axis that will be used for the space between the bars within the same category (default is .2 or 20%). The smaller this value is, the larger the bars will be.使用正边距和零没有得到任何结果后,我尝试对
itemMargin
使用负数来看看会发生什么。酒吧开始变粗。不过,我不知道是否建议这样做,因为如果没有足够的可用空间,您将会重叠。After getting no results using positive margins and zero, I tried using negative numbers for
itemMargin
to see what would happen. The bars started getting thicker. I don't know if this is recommended, though, since you will get overlap if there is not enough space available.根据 Dave Gilbert(JFreeChart 项目负责人)的说法
请参阅此处的讨论。
According to Dave Gilbert (JFreeChart Project Leader)
See the discussion here.