恐怕你得修改 JfreeChart 的代码,Opensource 很棒吗?
我的 BarChart 之前遇到过这个问题,我所做的是自定义 x 轴上的刻度,我只为 CategoryAxis.java 实现了这个。我希望这能给你一些启发。
请注意变量“tickInterval”,我将此属性添加到类中,例如您有1000个数字,如果将tickInterval设置为99,则只会显示0、100、200、300 ...。
对了,我的 freechart 版本是 1.0.5
public List refreshTicks(Graphics2D g2,
AxisState state,
Rectangle2D dataArea,
RectangleEdge edge) {
List ticks = new java.util.ArrayList();
// sanity check for data area...
if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
return ticks;
}
CategoryPlot plot = (CategoryPlot) getPlot();
List categories = plot.getCategoriesForAxis(this);
double max = 0.0;
if (categories != null) {
CategoryLabelPosition position
= this.categoryLabelPositions.getLabelPosition(edge);
float r = this.maximumCategoryLabelWidthRatio;
if (r <= 0.0) {
r = position.getWidthRatio();
}
float l = 0.0f;
if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
l = (float) calculateCategorySize(categories.size(), dataArea,
edge);
}
else {
if (RectangleEdge.isLeftOrRight(edge)) {
l = (float) dataArea.getWidth();
}
else {
l = (float) dataArea.getHeight();
}
}
int categoryIndex = 0;
Iterator iterator = categories.iterator();
while (iterator.hasNext()) {
Comparable category = (Comparable) iterator.next();
if(categoryIndex>0 && tickInterval>0)
{
if((categoryIndex+1) % (tickInterval+1) > 0)
{
category = "";
}
}
TextBlock label = null;
if(tickInterval> 0)
{
label = this.createSingleLabel(category, l * r, edge, g2);
}
else
{
label = createLabel(category, l * r, edge, g2);
}
if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
max = Math.max(max, calculateTextBlockHeight(label,
position, g2));
}
else if (edge == RectangleEdge.LEFT
|| edge == RectangleEdge.RIGHT) {
max = Math.max(max, calculateTextBlockWidth(label,
position, g2));
}
Tick tick = new CategoryTick(category, label,
position.getLabelAnchor(), position.getRotationAnchor(),
position.getAngle());
ticks.add(tick);
categoryIndex = categoryIndex + 1;
}
}
state.setMax(max);
return ticks;
}