Picture_2
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;
}