Few Questions

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ronan

Few Questions

Post by Ronan » Wed Aug 16, 2000 4:10 pm

Hi David
A few questions for you.


1) I have drawn a chart with a lot of values & labels on the horizontal axis. How can I display all these labels?

I have seen the discussion where you suggested using the Number Axis

NumberAxis myHorizontalAxis =
(NumberAxis) chart.getPlot().getAxis(Plot.HORIZONTAL_AXIS);
myHorizontalAxis.setAutoTickUnits(false);
myHorizontalAxis.setTickUnits(new Double(1.0));


However I get a ClassCast Exception trying to convert from Axis to NumberAxis.
How can I access the methods in NumberAxis after returning an Axis object?


2) I do not want to display the series - how do I switch it off?
I have tried passing in an empty String array but the box with the colour of the series line still appears.



thanks for your time
/Ronan

David Gilbert

RE: Few Questions

Post by David Gilbert » Thu Aug 17, 2000 6:12 am

Ronan wrote:

> 1) I have drawn a chart with a lot of values & labels on the
> horizontal axis. How can I display all these labels?
>
> <snip>
>
> However I get a ClassCast Exception trying to convert from Axis
> to NumberAxis.
> How can I access the methods in NumberAxis after returning an
> Axis object?

NumberAxis and CategoryAxis are in different branches of the Axis class hierarchy, so the cast won't work.

If you are using a HorizontalCategoryAxis, then there is a flag (verticalCategoryLabels) that controls whether or not the labels are drawn "vertically" - with vertical labels, you can fit more categories in without the labels overlapping.

It's another one of these attributes where I forgot to add methods to get and set the value - you can set it from the constructor, but not anywhere else. Add the following methods to HorizontalCategoryAxis:

/** Returns a flag indicating whether or not the tick labels on the axis should be drawn
vertically. */
public boolean getVerticalCategoryLabels() {
return this.verticalCategoryLabels;
}

/** Sets a flag that determines whether or not the tick labels on the axis should be drawn
vertically. If the value changes, an AxisChangeEvent is sent to all registered listeners.
@param flag The new value of the flag; */
public void setVerticalCategoryLabels(boolean flag) {
if (this.verticalCategoryLabels!=flag) {
this.verticalCategoryLabels = flag;
this.notifyListeners(new AxisChangeEvent(this));
}
}

> 2) I do not want to display the series - how do I switch it off?
> I have tried passing in an empty String array but the box with
> the colour of the series line still appears.

Do you mean the legend? Just use chart.setLegend(null);

Locked