setRange

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

setRange

Post by setRange » Wed Jun 12, 2002 2:04 pm

Hello,

I have an overlaid chart. Values in my dataset range from 0 to 20000.
Is it possible to set the range of my Y axis for example from 8000-9000 so that I see that region(8000-9000) more in detail?
I tried the setRange method but it doesn't seem to do what I want:
...
NumberAxis yAxis = new VerticalNumberAxis(label);
yAxis.setCrosshairVisible(false);
yAxis.setAxisRange(8900, 9000);
...

Isabelle Gheysens

Thanx in advance!

setRange

Re: setRange

Post by setRange » Thu Jun 13, 2002 8:59 am

Hi,

Is there anybody who can help me with this?

Thanx!!!

Isabelle

David Gilbert

Re: setRange

Post by David Gilbert » Thu Jun 13, 2002 9:19 am

Hi Isabelle,

You are creating a new axis...do you then add it to the plot? You can use the setRangeAxis(...) method in XYPlot to do that if you aren't already.

Alternatively, you can fetch the axis from the plot first:

NumberAxis axis = (NumberAxis)myPlot.getRangeAxis();

The reorganisation of the axes and datasets in 0.9.0 has broken the event notification so you may still not see the chart updating correctly. I have fixed this (as far as I can tell) in the CVS version and will be releasing 0.9.1 tomorrow. Let me know if it doesn't work...

Regards,

DG.

setRange

Re: setRange

Post by setRange » Thu Jun 13, 2002 1:43 pm

Hi David,

Thanx for your response!

The setRange method works, but I can't get it to work in a combined chart(I have a vertical combined chart which consists of two overlaid charts);
I'd like to set the range for each of the overlaid charts.

I also tried this with the JFreeChartDemo and there I had the same problem!

At first I thought the problem was that I used a combined chart, but I only see the problem when using overlaid charts.

I added one line of code to "displayOverlaidChart() " in "JFreeChartDemo" to reproduce this:

valueAxis.setAxisRange(171, 175);




private void displayOverlaidChart() {

if (this.overlaidChartFrame==null) {

// create a default chart based on some sample data...
String title = this.resources.getString("combined.overlaid.title");
String subtitleStr = this.resources.getString("combined.overlaid.subtitle");
String domain = this.resources.getString("combined.overlaid.domain");
String range = this.resources.getString("combined.overlaid.range");

// calculate High-Low and Moving Average Dataset
HighLowDataset highLowData = DemoDatasetFactory.createSampleHighLowDataset();
MovingAveragePlotFitAlgorithm mavg = new MovingAveragePlotFitAlgorithm();
mavg.setPeriod(5);
PlotFit pf = new PlotFit(highLowData, mavg);
XYDataset maData = pf.getFit();

// make master Dataset as combination of highLowData and the MA
CombinedDataset data = new CombinedDataset();
data.add(highLowData);
data.add(new SubSeriesDataset(maData, 1)); // extract MA series from maData as demo

// decompose data into its two dataset series
SeriesDataset series0 = new SubSeriesDataset(data, 0); // high-low series
SeriesDataset series1 = new SubSeriesDataset(data, 1); // MA data

// this code could probably go later in the ChartFactory class
JFreeChart chart = null;

// common horizontal and vertical axes
ValueAxis timeAxis = new HorizontalDateAxis(domain);
timeAxis.setCrosshairVisible(false);
NumberAxis valueAxis = new VerticalNumberAxis(range);
/////////////////////////////////////////////////////////////////////////////////////////
valueAxis.setAxisRange(45, 50);

valueAxis.setCrosshairVisible(false);

// make an overlaid CombinedPlot
CombinedPlot overlaidPlot = new CombinedPlot(timeAxis, valueAxis);

// add the sub-plots
overlaidPlot.add(ChartFactory.createCombinableHighLowChart(timeAxis, valueAxis, series0)); // high-low
overlaidPlot.add(ChartFactory.createCombinableTimeSeriesChart(timeAxis, valueAxis, series1)); // MA

// call this method after all sub-plots have been added
overlaidPlot.adjustPlots();

// make the top level JFreeChart object
chart = new JFreeChart(data, overlaidPlot, title, JFreeChart.DEFAULT_TITLE_FONT, true);


// then customise it a little...
TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
chart.addTitle(subtitle);
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

// and present it in a frame...
overlaidChartFrame = new JFreeChartFrame(title, chart);
overlaidChartFrame.pack();
JRefineryUtilities.positionFrameRandomly(overlaidChartFrame);
overlaidChartFrame.show();

}
else {
overlaidChartFrame.show();
overlaidChartFrame.requestFocus();
}

}

setRange

Re: setRange

Post by setRange » Thu Jun 13, 2002 1:45 pm

Am I doing something wrong or is this a bug?
Does anyone has a solution for my problem?

Thanx!

Isabelle

David Gilbert

Re: setRange

Post by David Gilbert » Thu Jun 13, 2002 4:31 pm

With combined charts pre 0.9.0 it can be difficult to get hold of the right axis. In 0.9.0, shared axes are maintained by the parent plot and set to null for the subplots, so it is easier to get working. I'd recommend trying out the latest version - or 0.9.1 which I am releasing tomorrow (to fix a few bugs that I introduced in 0.9.0).

Regards,

DG.

setRange

Re: setRange

Post by setRange » Fri Jun 14, 2002 10:40 am

Thanx!

The problem is solved using 0.9.0!

Isabelle

Locked