CombinedDomainXYPlot, multiple Ranges & XYLineAndShapeRe

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hsp707
Posts: 18
Joined: Thu May 15, 2008 4:58 pm

CombinedDomainXYPlot, multiple Ranges & XYLineAndShapeRe

Post by hsp707 » Sat Oct 04, 2008 8:26 pm

Picture_1

Image

Picture_2

Image

Is it even possible to do what I am trying to do here??

I am trying to make a XY chart with common domain axis but different range axis.
Each of these range axis has different scales (i.e. lower bound/upper bound and tick units etc.)
And each of these range axis should be displayed at bottom, one after another as shown in the attached images.

http://www.flickr.com/photos/31066816@N05/2912944150/
http://www.flickr.com/photos/31066816@N05/2912944186/

I want to display different shape/symbol for every data item belonging to different series and domain/range combination.
I am using XYLineAndShapeRenderer to display the symbols, which is good enough (although I would want to display customized images)
Now my problem is that, if I use one dataset with say 2 series, it will plot the different color symbols - which is good.
But I noticed that the values for 2nd series are not being plotted against second axis
i.e. Co2 as shown in picture_2. It is same as if there is no 2nd axis.

If you notice in the code below, I have one data set( has one series for wc and one for co2)
subplot1.setDataset(0, wcDataSet);
and renderer then displays blue for WC and red symbols for Co2, as shown in picture 2.
http://www.flickr.com/photos/31066816@N05/2912944150/
However, the red ones are not plotted right (i.e. not against range axis of CO2)

And if I change it to use two different datasets (each data set has one series, wcDataSet for wc and coDataSet has for Co2), like this
subplot1.setDataset(0, wcDataSet);
subplot1.setDataset(1, coDataSet);

Then I get chart as shown in picture_1

http://www.flickr.com/photos/31066816@N05/2912944186/

In this case, Co2 values are plotted against Co2 range axis, but all the plotted items are blue and their shape is same too.
I can not distinguish between which one belongs to WC and CO2 axis series.

I guess this is because of XYLineAndShapeRenderer, which applies to all charts in CombinedDomainXYPlot. How can I have a CombinedDomainXYPlot
with different range axis (with different units/scales) and display different symbols/colors for their data items and still display them
as shown in attached pictures. Please, if some one can tell me that it is even possible to do this. Any help/tips/suggestions will be appreciated.
Thanks a lot.

Code: Select all

public JFreeChart testChart(XYDataset wcDataSet, XYDataset coDataSet) {
		
		JFreeChart combinedChart1 = null;
		JFreeChart chart = null;
	
		CombinedDomainXYPlot combinedPlot1 = new CombinedDomainXYPlot(
				new NumberAxis("Depth"));
				
		NumberAxis wcRangeAxis = new NumberAxis("WC(%)");
		NumberAxis coRangeAxis = new NumberAxis(
				"CO2(%)");
		NumberTickUnit numberDomainTickUnit = new NumberTickUnit(5);
		
		XYPlot subplot1 = new XYPlot();
		
		
		subplot1.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
		subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
		
		subplot1.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
		
			
		subplot1.setRangeAxis(0,wcRangeAxis);
		subplot1.setRangeAxis(1, coRangeAxis);
		
		subplot1.getRangeAxis(0).setLowerBound(0);
		subplot1.getRangeAxis(0).setUpperBound(100);
		subplot1.getRangeAxis(1).setLowerBound(0);
		subplot1.getRangeAxis(1).setUpperBound(80);
		
	
		subplot1.getRangeAxis(0).setStandardTickUnits(
				NumberAxis.createIntegerTickUnits());
		subplot1.getRangeAxis(1).setStandardTickUnits(
				NumberAxis.createIntegerTickUnits());
			
		subplot1.setDataset(0, wcDataSet);
		
				
		subplot1.mapDatasetToRangeAxis(0, 0);
		
	
		
	    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
	    renderer.setSeriesPaint(0, Color.BLUE);
	    renderer.setSeriesLinesVisible(0, false);
	    renderer.setSeriesShapesVisible(0, true);
	    renderer.setSeriesPaint(1, Color.RED);
	    renderer.setSeriesLinesVisible(1, false);
	    renderer.setSeriesShapesVisible(1, true); 
       
	    subplot1.setRenderer(renderer); 
		
		combinedPlot1.add(subplot1);
		combinedPlot1.setGap(0);
		
		combinedPlot1.setOrientation(PlotOrientation.HORIZONTAL);
		combinedPlot1.getDomainAxis().setLowerBound(0);
		combinedPlot1.getDomainAxis().setUpperBound(150);
		combinedPlot1.getDomainAxis().setInverted(true);

		combinedPlot1.getDomainAxis().setStandardTickUnits(
				NumberAxis.createIntegerTickUnits());

		combinedChart1 = new JFreeChart("Demo1",
				JFreeChart.DEFAULT_TITLE_FONT, combinedPlot1, true);
				
		combinedChart1.getXYPlot().setDomainAxisLocation(
				AxisLocation.BOTTOM_OR_LEFT);

		combinedChart1.getXYPlot().setDomainCrosshairVisible(false);
		combinedChart1.getXYPlot().setRangeCrosshairVisible(false);
		return combinedChart1;

	}
Thanks Again!!

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Post by paradoxoff » Sat Oct 04, 2008 10:18 pm

Unfortunately, I have no experience with the combined plot classes, but I do not think that their use is the origin of your problem.
If I neglect the combined stuff, I assume that you want to achieve the following:
You have two series that you want to plot against the same domain axis but against different range axes since the range of the y values is different for the two series.

To achieve this, you have tried two different approaches:

1. Stuff the two series into a single dataset. In order for this to work you would need to map the individual series of a dataset to different range axes. This is not possible!
You can only map an entire dataset to a range axis. As you have seen, in this case the range of the (one and only) range axis will be used to show all series of the dataset.

2. Stuff the series into two different datasets and map each dataset to the range axis with the desired range. As you have noted, this causes the data points to be plotted at the right position but not in the right color!

I checked your code and I have noted that you only use one renderer that is not assigned to a specific index. If you do so, this renderer will be used to render all series of all datasets, and each series with the same index (e. g. each first series of the individual datasets) will be rendered in the same way.
All you have to do is to create a second renderer and assign that to the plot via

Code: Select all

plot.setRenderer(1, theNewRenderer)
The renderers of an XYPlot are indexed in the same way as the datasets. For the n-th dataset, the n-th renderer will be used (or the 0-th if no n-th renderer has been assigned to the plot). The color for the m-th series of the n-the dataset is retrieved by plot.getRenderer(n).getSeriesPaint(m).
That should work for a plain (i.e. "uncombined") XYPlot. Not sure how a combined XYPlot will behave.

hsp707
Posts: 18
Joined: Thu May 15, 2008 4:58 pm

Post by hsp707 » Sun Oct 05, 2008 4:50 pm

Thank you for your reply paradoxoff.
That's exactly my problem - you explained it much better than I did.
I will try what you have suggested and see if it works.

Thanks again.

hsp707
Posts: 18
Joined: Thu May 15, 2008 4:58 pm

Post by hsp707 » Mon Oct 06, 2008 9:17 pm

It worked.

Thanks a lot.

Locked