XYPlot setting visible range?

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

XYPlot setting visible range?

Post by Alex » Mon Feb 03, 2003 10:39 pm

Hi:

I am using the XYPlot class in coordination with the TimeSeriesDataPair class. I want to be able to dynamically change the range for the X Axis.
For example, I have a time series that goes from January 2002 - July 2002,
I want to be able to call the XYPlot object and limit the data displayed to
February 2002 - May 2002.

In addition, could you tell me how I can get the min and max months displayed by the XYPlot.



As always thanks for your help,

Alex

David Gilbert

Re: XYPlot setting visible range?

Post by David Gilbert » Tue Feb 04, 2003 5:40 pm

You need to understand that the XYPlot class ultimately works with numbers (double primitives). So any dates from your TimeSeriesCollection will be converted into "the number of milliseconds since 1-Jan-1970" before being plotted. The DateAxis classes work with these numbers, converting to java.util.Date only at the point that labels need to be displayed.

Knowing that info, you can set the axis range (which is what controls the amount of data visible on the chart) using the setRange(...) method in the DateAxis class:

XYPlot plot = myChart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setRange(...);

Regards,

Dave Gilbert

viswa

Re: XYPlot setting visible range?

Post by viswa » Fri Feb 14, 2003 5:07 am

Hi Dave,

Could you please send me some sample programs which generate multiple linecharts as it is very urgent to me.
I have this sample program.

*****************
DatasetProducer categoryData = new DatasetProducer() {
public Object produceDataset(Map params) {
final String[] categories = {"apples", "pies", "bananas", "oranges"};
final String[] seriesNames = {"Peter", "Helga", "Franz", "Olga"};
final Integer[][] startValues = new Integer[seriesNames.length][categories.length];
final Integer[][] endValues = new Integer[seriesNames.length][categories.length];
for(int series = 0; series < seriesNames.length; series ++){
for(int i = 0; i < categories.length; i++){
int y = (int)(Math.random() * 10 + 1);
startValues[series] = new Integer(y);
endValues[series] = new Integer(y + (int)(Math.random() * 10));
}
}
DefaultIntervalCategoryDataset ds = new DefaultIntervalCategoryDataset(seriesNames, categories, startValues, endValues);
return ds;
}
};
******************************
It is generating chart with defualt range.
But how can i change the range in Y-axis .
if i want to add some lables in the chart ,what should be the procedure.

hoping to get the early response..

Thanks,
viswa

Locked