List of usage examples for org.jfree.chart.plot XYPlot setRangeAxisLocation
public void setRangeAxisLocation(int index, AxisLocation location, boolean notify)
From source file:OAT.ui.BarChartFrame.java
public void addDataset(ChartDataset dataset) { if (dataset == null || dataset.getSeriesCount() == 0) { return;/*from w w w . ja va2 s . c o m*/ } XYPlot plot = getChart().getXYPlot(); int i = plot.getDatasetCount(); for (int j = 0; j < i; j++) { if (plot.getDataset(j).equals(dataset)) { // System.out.println("eq " + i // + " " + ((ChartDataset) plot.getDataset(j)).getTitle() // + " " + dataset.getTitle()); return; } } plot.setDataset(i, dataset); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); Double[] range = dataset.getAxisRange(); //axis int axisId = 0; if (range != null) { // if (range == null || range.length < 2) { // plot.mapDatasetToRangeAxis(i, 0); // } else { //scan for equal axis range, reuse if found boolean hasSameRange = false; if (range.length > 1) { for (int j = 1; j < plot.getRangeAxisCount(); j++) { Range otherRange = plot.getRangeAxis(j).getRange(); if (otherRange != null && otherRange.getLowerBound() == range[0] && otherRange.getUpperBound() == range[1]) { axisId = j; hasSameRange = true; break; } } } if (!hasSameRange) { NumberAxis newAxis = new NumberAxis(); if (range.length > 1) { newAxis.setAutoRange(false); newAxis.setRange(range[0], range[1]); } if (range.length > 2) { newAxis.setAutoTickUnitSelection(false, false); newAxis.setTickUnit(new NumberTickUnit(range[2])); } newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER); // newAxis.setAxisLinePaint(new Color(100, 0, 0)); // newAxis.setLabelPaint(paints[i][0]); // newAxis.setTickLabelPaint(paints[i][0]); // newAxis.setTickMarkPaint(paints[i][0]); // newAxis.setTickLabelsVisible(true); axisId = plot.getRangeAxisCount(); plot.setRangeAxis(axisId, newAxis, false); plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false); } // plot.mapDatasetToRangeAxis(i, newAxisId); } plot.mapDatasetToRangeAxis(i, axisId); // //renderer XYLineAndShapeRenderer renderer; if (dataset instanceof TradeDataset) { renderer = new TradeRenderer(); for (int j = 0; j < dataset.getSeriesCount(); j++) { renderer.setSeriesLinesVisible(j, false); } } else { Shape shape = Main.defaultShape; Paint[][] seriesPaints; Stroke stroke; if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) { seriesPaints = Main.greyPaints; stroke = Main.dottedStoke; } else { seriesPaints = Main.defaultPaints; stroke = Main.defaultStoke; } renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke); } plot.setRenderer(i, renderer, false); }