zooming in a combined chart

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

zooming in a combined chart

Post by Charles Martin » Wed Sep 04, 2002 9:10 pm

Hello,

I am newbie and have a question regarding a feature.

I am trying to create a CombinedXYPlot, and allow zooming acrcoss the charts, synchronized so that if the user zooms 1 chart, all the other charts also zoom.

I find that if I create a CombinedXYPLot, add it to the ChartPanel, and then try to zoom, I get a null pointer exception on zoom()...although the charts do zoom properly.

I am wondering if this is a bug, or if I have configured something incorrectly


Code to follow:

/**
* Creates a combined and overlaid chart.
*/
public static JFreeChart createCombinedAndOverlaidChart() {

// create a default chart based on some sample data...
String title = "title";
String subtitleStr = "subtitle";
String domain = "DOMAIN";

XYDataset data1 = createLargeDataSet();
XYDataset data2 = createLargeDataSet();

// create master Dataset
CombinedDataset data = new CombinedDataset();
data.add(data1);
data.add(data2);


// CombinedDataset data1 = new CombinedDataset(new SeriesDataset[] {series0, series1} );
int n = 2; // number of combined (vertically laidout) charts


NumberAxis valueAxis = new VerticalNumberAxis("RANGE");
valueAxis.setAutoRangeIncludesZero(false); // override default
HorizontalDateAxis dateAxis = new HorizontalDateAxis(domain);

// create CombinedPlot...
CombinedXYPlot multiPlot = new CombinedXYPlot(dateAxis,
CombinedXYPlot.VERTICAL);

// add subplot1...
XYPlot subplot1 = new XYPlot(data1, null, valueAxis);
multiPlot.add(subplot1, 1);
XYPlot subplot2 = new XYPlot(data2, null, valueAxis);
multiPlot.add(subplot2, 2);


// now create the master JFreeChart object
JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), multiPlot, true);

chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white,0, 1000, Color.blue));
return chart;

}

/**
* Creates a combined and overlaid chart.
*/
public static JFreeChart createCombinedAndOverlaidChart() {

// create a default chart based on some sample data...
String title = "title";
String subtitleStr = "subtitle";
String domain = "DOMAIN";

XYDataset data1 = createLargeDataSet();
XYDataset data2 = createLargeDataSet();

// create master Dataset
CombinedDataset data = new CombinedDataset();
data.add(data1);
data.add(data2);


// CombinedDataset data1 = new CombinedDataset(new SeriesDataset[] {series0, series1} );
int n = 2; // number of combined (vertically laidout) charts


NumberAxis valueAxis = new VerticalNumberAxis("RANGE");
valueAxis.setAutoRangeIncludesZero(false); // override default
HorizontalDateAxis dateAxis = new HorizontalDateAxis(domain);

// create CombinedPlot...
CombinedXYPlot multiPlot = new CombinedXYPlot(dateAxis,
CombinedXYPlot.VERTICAL);

// add subplot1...
XYPlot subplot1 = new XYPlot(data1, null, valueAxis);
multiPlot.add(subplot1, 1);
XYPlot subplot2 = new XYPlot(data2, null, valueAxis);
multiPlot.add(subplot2, 2);


// now create the master JFreeChart object
JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), multiPlot, true);

chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white,0, 1000, Color.blue));
return chart;

}

David Gilbert

Re: zooming in a combined chart

Post by David Gilbert » Wed Sep 04, 2002 11:09 pm

The combined charts don't behave well with zooming, it needs to be worked on.

Regards,

DG.

Samiul

Re: zooming in a combined chart

Post by Samiul » Thu Sep 05, 2002 8:38 am

Hi !!!
I was facing the same problem and in fact I have posted request for help on this in my topic ("Time Series Chart with Vertical Bar Chart"). Since I didn't get any replies on it, I set to work on the problem and managed to overcome it.
The workaround is to put a "not null" check in the following functions in ChartPanel.java----

1. zoomInHorizontal
2. zoomInVertical
3. zoomOutHorizontal
4. zoomOutVertical
5. zoom
6. autoRangeHorizontal
7. autoRangeVertical

Wherever u find something like "axis.XXXXXXX()", put a "if (axis!=null) axis.XXXXX()" statement in all of the above methods.

David Gilbert

Re: zooming in a combined chart

Post by David Gilbert » Thu Sep 05, 2002 8:54 am

Hi Samiul,

Thanks for the suggestion, I'll try it out.

Regards,

DG

Charles Martin

Re: zooming in a combined chart

Post by Charles Martin » Thu Sep 05, 2002 6:18 pm

Thanks for the suggestion.

Note that when the vertical zoom is activated, the horizontal zoom works across multiple charts, although exceptions are thrown.

This behavior is not bad, although the ideal situation for me would be to auto-rescale the vertical axis of every chart when zooming in a selected chart.

I also find is that the multi plot / ChartPanel only allows mouse evenst in the bottom most chart. I was planning to remedy this as well, and create a multiChartPanel. It looks like I will have to modify some of the other classes as well, such as ChartRenderer and JFreeChart.

If anyone is interested in this, please let me know and I'll keep you posted on my progress.

There are some other features I have to add as well, such as allowing the user to draw lines (i.e. price support lines).

Charles

Locked