Problem with overlaid charts

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

Problem with overlaid charts

Post by Nico » Tue Apr 23, 2002 1:50 pm

Hi,
I'm trying to make overlayed charts, so first I'm making an empty chart. Then, using the setDataset(), I add a LineChart in my first generated chart, here is the code :

public class MyLineChartPanel extends JPanel {

/** la graphique */
private JFreeChart _myChart;

/** le panel contenant le graphique */
private JFreeChartPanel _chartPanel;

public MyLineChartPanel(int width, int height, int x, int y) {

super();

this.setSize(width, height);
this.setLocation(x,y);

HorizontalDateAxis hAxis = new HorizontalDateAxis("Dates");
VerticalNumberAxis vAxis = new VerticalNumberAxis("Nb");
vAxis.setStandardTickUnits(TickUnits.createIntegerTickUnits());

/* Construction du graphique */
_myChart = new JFreeChart(new CombinedDataset(), new CombinedPlot(hAxis, vAxis), "titre du graphique", JFreeChart.DEFAULT_TITLE_FONT, true);

_chartPanel = new JFreeChartPanel(
_myChart,
width,
height,
width,
height,
true, //useBuffer
false, // properties
false, // save
true, // print
true, // zoom
true //tooltip
);

this.add(_chartPanel);

}

public void setDataset(XYDataset dataset) {

CombinedDataset combinedDataset = new CombinedDataset();
combinedDataset.add(dataset);

SeriesDataset series0 = new SubSeriesDataset(combinedDataset, 0);

CombinedPlot overlaidPlot = (CombinedPlot)_myChart.getPlot();

XYPlot xyplot = new XYPlot((HorizontalDateAxis)overlaidPlot.getHorizontalAxis(), (VerticalNumberAxis)overlaidPlot.getVerticalAxis());
xyplot.setXYItemRenderer(new MyXYItemRenderer(MyXYItemRenderer.SHAPES_AND_LINES));

CombinedChart lineChart = new CombinedChart(series0, xyplot);

// add the sub-plots
overlaidPlot.add(lineChart);

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

/* Construction du graphique */
_myChart.setDataset(combinedDataset);
}
}

But when I execute the code, I ge the following exception :

java.lang.ClassCastException: com.jrefinery.chart.HorizontalDateAxis
at com.jrefinery.chart.combination.CombinedPlot.getRange(CombinedPlot.java:676)
at com.jrefinery.chart.combination.CombinedPlot.adjustPlotsMinMax(CombinedPlot.java:903)
at com.jrefinery.chart.combination.CombinedPlot.readjustPlotsMinMax(CombinedPlot.java:758)
at com.jrefinery.chart.combination.CombinedPlot.chartChanged(CombinedPlot.java:722)
at com.jrefinery.chart.JFreeChart.notifyListeners(JFreeChart.java:698)
at com.jrefinery.chart.JFreeChart.setDataset(JFreeChart.java:385)
at stats.gui.MyLineChartPanel.setDataset(MyLineChartPanel.java:99)

It seems that the CombinedPlot object uses CombinedAxis, and not HorizontalDateAxis, but my code is based on the overlaid chart example of JFreeChartDemo (which is similar).
What's wrong ?
thanxs,
Nico

Nico

Re: Problem with overlaid charts

Post by Nico » Tue Apr 23, 2002 2:18 pm

re-Hi,
Finally I found a solution, maybe it is a bug, maybe not. I hacked the CombinedPlot class, and I add the following lines in the public List getVerticalAxes(boolean recursive) and public List getHorizontalAxes(boolean recursive) methods :
if (chartInfo.plot instanceof CombinedPlot)
before the result.add(...) statement.

David Gilbert

Re: Problem with overlaid charts

Post by David Gilbert » Tue Apr 23, 2002 4:11 pm

I've been working on the combined plots and I think I can make everything work with just two classes (I've called them OverlaidXYPlot and MultiXYPlot) that use only the standard datasets and axes. This makes everything a little cleaner and the bugs a little easier to spot. I hope to have the code committed in CVS by the end of the week if anyone wants to try it out.

Regards,

DG.

Nico

Re: Problem with overlaid charts

Post by Nico » Tue Apr 23, 2002 4:29 pm

I'm very interested in these classes. Could you send me some pieces of codes ?
Or may I have to wait until the end of the week ?..
Thanx,
Nico

Nico

Re: Problem with overlaid charts

Post by Nico » Tue Apr 23, 2002 5:19 pm

It seems that the bug I have detected is not a bug, but a misunderstood from me.
But I can not understand what is the CombinableAxis interface, and what is the relation between this class and the HorizontalDateAxis or VerticalValueAxis classes.
I'm a bit disapointed.

David Gilbert

Re: Problem with overlaid charts

Post by David Gilbert » Wed Apr 24, 2002 8:26 am

Nico wrote:
> I'm very interested in these classes. Could you send me some
> pieces of codes ?
> Or may I have to wait until the end of the week ?..

I've reduced the combined plot stuff to two classes (OverlaidXYPlot and MultiXYPlot) but this has required some reorganisation of the existing code which has resulted in changes to many classes. So it will be easiest to wait for the code to be committed to CVS.

Regards,

DG.

David Gilbert

Re: Problem with overlaid charts

Post by David Gilbert » Wed Apr 24, 2002 8:42 am

Nico wrote:
> But I can not understand what is the CombinableAxis
> interface, and what is the relation between this class and
> the HorizontalDateAxis or VerticalValueAxis classes.

In the revisions I am currently working on, the combined plots will work with standard axes, so some of that complexity is reduced...I hope!

DG.

Nico

Re: Problem with overlaid charts

Post by Nico » Wed Apr 24, 2002 9:06 am

Ok, thanks, I will check the CVS Tree very often.

David Gilbert

Re: Problem with overlaid charts

Post by David Gilbert » Wed Apr 24, 2002 5:20 pm

I've just committed the changes. I not completely finished yet, there are still one or two minor things to work on, but I'm happy with the way most of it is working.

DG.

Locked