CategoryAxis tick labels.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

CategoryAxis tick labels.

Post by msprauer » Wed Jul 11, 2007 5:06 pm

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?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jul 11, 2007 5:10 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

burningice
Posts: 5
Joined: Wed Jul 11, 2007 4:41 pm

Post by burningice » Wed Jul 11, 2007 5: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;
}

msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

Post by msprauer » Wed Jul 11, 2007 6:42 pm

thank you for your help guys, it'll definately come in handy.

Locked