关闭JFreeChart条形图中的空白区域 [英] Closing up blank space in JFreeChart bar chart

查看:144
本文介绍了关闭JFreeChart条形图中的空白区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JFreeChart 并希望显示玩家得分的条形图,其中y轴上的得分和x轴上的玩家游戏分组。

I am using JFreeChart and would like to display a bar chart of player's scores, with the score on the y-axis and the player's games grouped on the x-axis.

例如

String[] {Player name, score, game number}
Player 1, 10 , 1
Player 1, 12 , 2
Player 1, 15 , 3
Player 2, 11 , 1
Player 3, 18 , 1

因为玩家不必玩相同数量的游戏,所以这导致了创建dataSet时有很多空白区域,因为它试图为Player 2& 3场比赛2& 3。

Because the players do not have to play the same number of games, this results in a lot of blank space when the dataSet is created, as it tries to plot a bar for Player 2 & 3 games 2 & 3.

data.addValue(score, game number, player name);

输出:(数字不匹配,这只是我敲了一个快速测试)

Output: (the numbers dont quite match, this was just a quick test I knocked up)

任何人都可以帮我解决这个空白区域的问题吗?从理论上讲,玩家1可以继续玩2个玩家,玩家2和玩家只玩3个,所以看起来很荒谬!
我是JFreeChart的新手,所以可能有一个明显的解决方案!

Can anybody help me with how to close up this blank space? In theory player 1 could go on to play 100s of games with player 2 and 3 playing only a few, so it would look quite ridiculous! I am new to JFreeChart so there is probably an obvious solution!

提前感谢您的帮助。

推荐答案

首先仔细查看图片

First Look at the Picture carefully

这是一些解释wrt Numbers。

Here is some Explanation w.r.t Numbers.


  1. setLowerMargin (双边距)。

  2. setUpperMargin(双边距)。

  3. setCategoryMargin(双边距)。

  4. setItemMargin(双边距)。

  1. setLowerMargin(Double margin).
  2. setUpperMargin(Double margin).
  3. setCategoryMargin(Double margin).
  4. setItemMargin(Double margin).

以下是如何使用图表中的方法

Here is How you can use the methods in your chart

 CategoryPlot p = chart.getCategoryPlot(); 

 CategoryAxis axis = p.getDomainAxis();
 axis.setLowerMargin(0.1);
 axis.setUpperMargin(0.1);
 axis.setCategoryMargin(0.1);
 BarRenderer renderer = (BarRenderer) p.getRenderer();
 renderer.setItemMargin(0.1); 

您可以设置介于0.0到1.0之间的值(示例0.1表示10%)

You can set the value between 0.0 to 1.0 (example 0.1 means 10%)

希望这有助于

(更新后你的评论)
那么在这种情况下你应该使用 Layered Bar图表

这篇关于关闭JFreeChart条形图中的空白区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆