I want to create a single XYPlot based on two datasets and I want to have domain for each dataset. For the example, the first plot is an XYBarChart indicating the current planning (amount of money spend in the following weeks, domain [0,10]) and the second plot indicates some info from a related algorithm (range [0,100]).
What I want is to have both on the same plot. My point is that my second dataset is matched with the range of the first dataset. So, if I have the point in (-50,15) from the second dataset (the one in [-100,100]), it plots it as if it was a point of the first dataset (the one in [0,10]): rescaling the whole figure. Note that, for other aspects of the graph (one is based on lines and the other on bars), it works perfectly.
Do you know how I can solve this issue, please?
Thanks for any help!
Here is further detail about my code. The main function:
Code: Select all
private static JFreeChart consumptionAndCostCurveChart(Object cp)
{
XYPlot consumptionPlot = new XYPlot();
addConsumptionBars(cp,consumptionPlot);
addCostLines(cp,consumptionPlot);
JFreeChart jfc = new JFreeChart(consumptionPlot);
jfc.setTitle("hi");
return jfc;
}
Code: Select all
private static void addConsumptionBars(Object cp, XYPlot consumptionPlot) {
IntervalXYDataset consumptionDataset = getConsumptionDataset(cp);
consumptionPlot.setDataset(0,consumptionDataset);
consumptionPlot.setDomainAxis(0,new NumberAxis("Timeslot"));
NumberAxis rangeAxis = new NumberAxis("Energy");
if(minConsumptionMargin!=maxConsumptionMargin)
rangeAxis.setRange(minConsumptionMargin, maxConsumptionMargin);
consumptionPlot.setRangeAxis(0,rangeAxis);
XYBarRenderer renderer = new XYBarRenderer();
renderer.setShadowVisible(false);
renderer.setSeriesPaint(0, new Color(0.2f, 0.2f, 0.2f, 0.5f));
renderer.setSeriesPaint(1, new Color(0, 0, 1f, 1f));
renderer.setDrawBarOutline(false);
renderer.setBarPainter(new StandardXYBarPainter());
consumptionPlot.setRenderer(0,renderer);
}
Code: Select all
private static void addCostLines(Object cp, XYPlot consumptionPlot)
{
IntervalXYDataset costDataset = getCostDataSet(cp);
consumptionPlot.setDataset(1,costDataset);
NumberAxis domainAxis = new NumberAxis("Iteration");
domainAxis.setRange(-100,100);
consumptionPlot.setDomainAxis(1,domainAxis);
NumberAxis rangeAxis = new NumberAxis("Cost");
rangeAxis.setRange(-1000, 1000);
consumptionPlot.setRangeAxis(1,rangeAxis);
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesPaint(0, Color.black);
consumptionPlot.setRenderer(1,renderer);
}