I'm having the problem where I have many categories plotted, and I need some way of filtering the tick labels that are shown. Right now, with 50 or more categories, the labels turn to ellipses since there is not enough room for them.
Is it possible to only show selective tick labels on a CategoryAxis?
CategoryAxis tick labels.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
No. If your chart makes sense with category labels missing, then it's often a hint that your axis contains a value scale rather than a set of discrete categories...in which case you should use an XYPlot not a CategoryPlot.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 5
- Joined: Wed Jul 11, 2007 4:41 pm
I also met such a problem. My solution is to use a concrete class for category key instead of string. Like this:
--------------------------------------
public class MyCategoryKey implements Comparable {
private int id; /* or any other type for id, or just use key as id if the key is unique */
private String key;
private boolean visible;
// getters & setters
public MyCategoryKey(int id, String key, boolean visible) {
this.id = id;
this.key = key;
this.visible;
}
public String toString() {
return (visible ? key : "");
}
public int hashCode() {
return id;
}
public boolean equals(MyCategoryKey other) {
return id == other.id;
}
public int compareTo(MyCategoryKey other) {
//to do
}
}
-------------------------------------
In your code:
int X = 5; //show category label every 5 categories
int x = 0;
//in the loop, likely:
for(int index = 0; index < categoryCount; index++) {
boolean visible = (x == X);
MyCategoryKey catKey = new MyCategoryKey(id, key, visible)
x++;
if(x == X) x = 0;
}
--------------------------------------
public class MyCategoryKey implements Comparable {
private int id; /* or any other type for id, or just use key as id if the key is unique */
private String key;
private boolean visible;
// getters & setters
public MyCategoryKey(int id, String key, boolean visible) {
this.id = id;
this.key = key;
this.visible;
}
public String toString() {
return (visible ? key : "");
}
public int hashCode() {
return id;
}
public boolean equals(MyCategoryKey other) {
return id == other.id;
}
public int compareTo(MyCategoryKey other) {
//to do
}
}
-------------------------------------
In your code:
int X = 5; //show category label every 5 categories
int x = 0;
//in the loop, likely:
for(int index = 0; index < categoryCount; index++) {
boolean visible = (x == X);
MyCategoryKey catKey = new MyCategoryKey(id, key, visible)
x++;
if(x == X) x = 0;
}