manually setting the y-axis

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

manually setting the y-axis

Post by atom » Sat Jul 20, 2002 3:14 pm

hI

How can a set the y axis manually. I am plotting percentages and I want to plot 0-100% on my y axis. and the data i have is in the range 50-70% which should plot accordingly. At present I get an y-axis which says 50-70%.

reji

Re: manually setting the y-axis

Post by reji » Mon Jul 22, 2002 1:04 am

hi,

Try the following way.

Charts using XYDataset.
-------------------------------

XYPlot plot = chart.getXYPlot();
VerticalNumberAxis axis = (VerticalNumberAxis)plot.getRangeAxis();
axis.setAutoRange(false);
axis.setRange(min, max);

Charts using CategoryDataset
---------------------------------------

VerticalCategoryPlot plot = (VerticalCategoryPlot)chart.getPlot();
NumberAxis axis = (NumberAxis)plot.getRangeAxis();
axis.setAutoRange(false);
axis.setRange(min, max);


Regards,

Reji

reji

Re: manually setting the y-axis

Post by reji » Mon Jul 22, 2002 1:09 am

Hi,

In case of Charts using CategoryDataset, I think its better to use

VerticalCategoryPlot plot = (VerticalCategoryPlot)chart.getCategoryPlot();

instead of

VerticalCategoryPlot plot = (VerticalCategoryPlot)chart.getPlot();

regards,

reji

atom

Re: manually setting the y-axis

Post by atom » Mon Jul 22, 2002 11:28 am

Hello

Thanxs for that reiji it works just fine. Another quick question I used a code snippet from your earlier response to a fellow peer in the group.

HorizontalDateAxis axis = (HorizontalDateAxis)plot.getDomainAxis();
axis.setVerticalTickLabels(true);


I normally have my x-axis values to be;

10-July-2002 11-July-2002 12-July-2002 13-July-2002 14-july-2002

and so on but because they overlap I wanted to change them so they are vertical. When I tried the above the values were vertical but they were not the above values but hourly values over 24 hour period only for example

00:00 01:00 02:00 03:00 04:00 05:00....................................23:00

Why do I get the above and not my true values? I am using JdbcXYDataset which extracts the information as a (x-axis)Timestamp and its corresponding (y-axis)Temperature values from a database as Timeseries XYplot.



This is my code so far

// Create the chart

JFreeChart chart = ChartFactory.createTimeSeriesChart("Fire Alarm Report", "Time", "Temperature", dataset, true);

XYPlot plot = chart.getXYPlot();

VerticalNumberAxis axis = (VerticalNumberAxis)plot.getRangeAxis();
axis.setAutoRange(false);
axis.setMinimumAxisValue(0.0);
axis.setMaximumAxisValue(100.0);

HorizontalDateAxis axis = (HorizontalDateAxis)plot.getDomainAxis();
axis.setVerticalTickLabels(true);


Kind Regards
A>M

David Gilbert

Re: manually setting the y-axis

Post by David Gilbert » Mon Jul 22, 2002 11:52 am

The values (dates) on the axis aren't taken from your dataset...the axis is just a time line, and JFreeChart will (by default) try to display as many tick labels as it has room for without the labels overlapping. Try resizing some of the charts in the demo, and watch what happens to the tick labels on the axis, to see what I mean.

You can switch this 'autoTickUnitSelection' feature off by calling the setAutoTickUnitSelection(boolean) method in the ValueAxis class. After setting it to false, you should call the setTickUnit(...) method in the DateAxis class to control the tick size...it is up to you now to make sure the labels don't overlap.

Regards,

DG.

Locked