How can I remove the y labels from a JFreeChart chart? I use a NumberAxis
for my y axis.
I can't seem to find a simple method for this anywhere.
I would like something similar to the remove legend syntax:
// Remove the legend
chart.removeLegend();
Note that I do want to define the title in the NumberAxis
:
NumberAxis axis1 = new NumberAxis("A random title");
I simply don't want it to show up in the final chart.
I think that you mean that you want to hide the tick labels for the Y axis, but still want to see the label for the axis itself. Am I correct?
You can do that with:
axis1.setTickLabelsVisible(false);
Okay, if you want to:
NumberAxis
Then there is one solution, that isn't perfect either, that you could use. If you set the "attributed label" (a label with extra font markup attributes), it will draw the attributed label instead. You can set it to a single space (a zero-length string doesn't work - the font rendering code doesn't allow that).
rangeAxis.setAttributedLabel(" ");
At least axis1.getLabel()
will still return your old label, but that's the only benefit of this that I can see.
Otherwise, you can subclass NumberAxis
and override the method drawLabel
in the subclass to do nothing:
protected AxisState drawLabel(String label, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge,
AxisState state) {
return state;
}