setting axis labels, graph size...

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

setting axis labels, graph size...

Post by Jonathan » Thu Aug 10, 2000 3:47 am

Hi,
I'm having trouble trying to figue out how to set the axis labels that
I wish...
I wish to have an axis on an XYPlot show labe 1,2,3,4,5...24.
Instead I keep getting values calculated for me.. like 2.5, 5.0, 7.5
Since I need 1 - 24 since they represent each hour of the day.

Also how do I set the size of the graph????
The documentation is confusing on the above 2 matters... and i'm a little confused.

Thanks.
Jonathan.

David Gilbert

RE: setting axis tick units

Post by David Gilbert » Thu Aug 10, 2000 7:50 am

By default, NumberAxis sets the tick units automatically, and 2.5 is one of the standard values (defined in the NumberAxis.java file - you can change them, just be sure to change the corresponding format strings).

You can switch off the auto tick unit calculation, and set the tick units to 1.0, like this:

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

Of course, that would work if I had remembered to include the setTickUnits() method in NumberAxis - you'll have to add it yourself, I'll make sure it is in the next release:

public void setTickUnits(Number units) {
this.tickUnits = units;
notifyListeners(new AxisChangeEvent(this));
}

Regards,

DG.

David Gilbert

RE: setting graph size...

Post by David Gilbert » Thu Aug 10, 2000 8:01 am

It depends what you mean by the size...

JFreeChart is set up to draw to any Graphics2D object, which means you can draw to the screen, the printer or directly into a BufferedImage. The chart is drawn inside a Rectangle2D specified by the caller of the draw() method, so the chart can be any size you want.

If you are displaying a chart on the screen, then chances are you are using JFreeChartPanel, a wrapper around the JFreeChart class which automatically draws the chart inside a panel, at the correct size for the panel. So if this is the size you mean, then you just need to control the size of the panel as you would for any other AWT/Swing component (using a LayoutManager).

Regards,

DG.

Locked