Reputation: 103
I'm sure the answer is here somewhere but I really can't find it.
I have a LineChart with a lot of entries (lets say 1000). In the plot I can see (and adjust (see A)) the Y-axis perfectly well. Just the X-axis drives me nuts! With 1000 entries there is no number of the bottom of the plot.
A: With this I can adjust the Y-axis nicely. final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.00, 1.00); rangeAxis.setTickUnit(new NumberTickUnit(0.2)); rangeAxis.setVerticalTickLabels(false);
I wanna do the same with the X-axis.
Please help me out. Thanks a lot
-> problem with first answer | Domain axis with 100 numbers and an interval of 50
Upvotes: 1
Views: 2414
Reputation: 1350
I am afraid you have to modified the code of JfreeChart, Is Opensource great?
I have this problem before for my BarChart, What I did is to customize the tick on x-Axis I only implemented this for CategoryAxis.java alone. I hope this can shed some light on you.
Please note the variable "tickInterval", I added this property to the class, for example you have 1000 numbers, if set tickInterval as 99, only 0, 100, 200, 300 ... will show up.
bye the way, my freechart version is 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;
}
Upvotes: 2