Merge/Overlay two charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dmantamp
Posts: 2
Joined: Fri Oct 09, 2009 7:36 pm
antibot: No, of course not.

Merge/Overlay two charts

Post by dmantamp » Fri Oct 09, 2009 7:40 pm

Hi All,
Can anybody help me to in finding a sample code to merge two charts with same datataset. For example, I have a bar chart and a TimeSeries. I want to show it overlayed. Please help me.

Thanks
Deekshit M

Pookah
Posts: 4
Joined: Fri Jul 03, 2009 2:18 pm

Re: Merge/Overlay two charts

Post by Pookah » Sun Oct 11, 2009 8:48 am

If the solution in CombinedDomainCategoryPlot demo does not satisfy you (having a bar chart below, and time series above) then one way is to use JLayeredPane.

You would then add the two JFreeCharts to the panel, one below and other with a transparent background above... something like:

Code: Select all

lLayeredPane.add(barPlotChart, new Integer(0));
 lLayeredPane.add(timeSeriesChart, new Integer(1));	
And make sure that the background of the time series is transparent with:

Code: Select all

timeSeriesChart.setOpaque(false);
timeSeriesChart.setBackground(new Color(0, 0, 0, 0));
Cheers,

Nenad Bartonicek
EMBL-EBI

MitchBuell
Posts: 47
Joined: Thu Dec 11, 2008 7:59 pm

Re: Merge/Overlay two charts

Post by MitchBuell » Mon Oct 12, 2009 8:09 pm

JFreeChart also supports multiple charts in the same ChartPanel, which is like overlaying. The added benefit is that zooming will zoom in on both charts at the same time. http://www.jfree.org/phpBB2/viewtopic.p ... 883#p77685

Locked