Reputation: 1888
I have two series in a jFreeChart histogram. One is normally smaller then the other and we'd like to scale the smaller so it is similar to the larger series and I wanted to verify that it is possible to do this with jFreeChart's usual API and two separate range axis, presumably one on the right and the other on the left.
Upvotes: 1
Views: 623
Reputation: 1888
The official examples were quite helpful. Here is my solution based on them much thanks to trashgod's suggestion.
public void generateChart(List<FmsData> data, Valve valve) {
HistogramDataset aggDs = createAggDataset(data);
chart = createChart(aggDs, valve.getNumber());
HistogramDataset valveDs = createValveDataset(data,valve.getNumber());
XYPlot plot = chart.getXYPlot();
// configure the second dataset
plot.setDataset(0, aggDs);
plot.setDataset(1, valveDs);
plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
plot.mapDatasetToRangeAxis(0, 0);
plot.mapDatasetToRangeAxis(1, 1);
NumberAxis valveRangeAxis = new NumberAxis();
plot.setRangeAxis(1, valveRangeAxis);
XYBarRenderer renderer2 = new XYBarRenderer();
plot.setRenderer(1, renderer2);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
renderer2.setDrawBarOutline(false);
// flat bars look best...
renderer2.setBarPainter(new StandardXYBarPainter());
renderer2.setShadowVisible(false);
// end config second dataset
Upvotes: 1