Example usage for org.jfree.chart.plot XYPlot getRangeAxis

List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRangeAxis.

Prototype

public ValueAxis getRangeAxis() 

Source Link

Document

Returns the range axis for the plot.

Usage

From source file:edu.ucla.stat.SOCR.chart.SuperBubbleChart.java

/**
 * Creates a chart./*w w w.j av a 2  s .  com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYZDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBubbleChart(chartTitle, // chart titl                          
            rangeLabel, // y axis label
            domainLabel, // x axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setLegendItemLabelGenerator(new SOCRXYZSeriesLabelGenerator());

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.15);
    domainAxis.setUpperMargin(0.15);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java

protected void configureLineChart(final XYPlot plot) {
    final XYDataset linesDataset = createLinesDataset();
    if (linesDataset == null || linesDataset.getSeriesCount() == 0) {
        return;/*w w  w  . j av  a  2 s  . com*/
    }

    //Create Axis Objects
    final ValueAxis linesAxis;
    if (isSharedRangeAxis()) {
        linesAxis = plot.getRangeAxis();
    } else if (isThreeD()) {
        linesAxis = new NumberAxis3D(getSecondValueAxisLabel());
    } else {
        linesAxis = new NumberAxis(getSecondValueAxisLabel());
    }

    final XYItemRenderer lineRenderer;
    if (isThreeD()) {
        lineRenderer = new XYLine3DRenderer();
    } else {
        lineRenderer = new XYLineAndShapeRenderer();
    }

    plot.setRenderer(1, lineRenderer);
    plot.setDataset(1, linesDataset);
    plot.setRangeAxis(1, linesAxis);

    //map lines to second axis
    plot.mapDatasetToRangeAxis(1, 1);

    //set location of second axis
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
}

From source file:LineChartDemo6.java

/**
 * Creates a chart.//from w w  w  . ja  v a 2 s.c om
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

/**
 * Handles an action event./*w  w  w  .j  a va 2  s  .  co  m*/
 * 
 * @param evt
 *            the event.
 */
public void actionPerformed(ActionEvent evt) {
    try {
        String acmd = evt.getActionCommand();

        if (acmd.equals(ACTION_CHART_ZOOM_BOX)) {
            setPanMode(false);
        } else if (acmd.equals(ACTION_CHART_PAN)) {
            setPanMode(true);
        } else if (acmd.equals(ACTION_CHART_ZOOM_IN)) {
            ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
            Rectangle2D rect = info.getPlotInfo().getDataArea();
            zoomBoth(rect.getCenterX(), rect.getCenterY(), ZOOM_FACTOR);
        } else if (acmd.equals(ACTION_CHART_ZOOM_OUT)) {
            ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
            Rectangle2D rect = info.getPlotInfo().getDataArea();
            zoomBoth(rect.getCenterX(), rect.getCenterY(), 1 / ZOOM_FACTOR);
        } else if (acmd.equals(ACTION_CHART_ZOOM_TO_FIT)) {

            // X-axis (has no fixed borders)
            chartPanel.autoRangeHorizontal();
            Plot plot = chartPanel.getChart().getPlot();
            if (plot instanceof ValueAxisPlot) {
                XYPlot vvPlot = (XYPlot) plot;
                ValueAxis axis = vvPlot.getRangeAxis();
                if (axis != null) {
                    axis.setLowerBound(yMin);
                    axis.setUpperBound(yMax);
                }
            }
        } else if (acmd.equals(ACTION_CHART_EXPORT)) {
            try {
                chartPanel.doSaveAs();
            } catch (IOException i) {
                MsgBox.error(i.getMessage());
            }
        } else if (acmd.equals(ACTION_CHART_PRINT)) {
            chartPanel.createChartPrintJob();

        } else if (acmd.equals(ACTION_CHART_PROPERTIES)) {
            ChartPropertyEditPanel panel = new ChartPropertyEditPanel(jFreeChart);
            int result = JOptionPane.showConfirmDialog(this, panel,
                    localizationResources.getString("Chart_Properties"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE);
            if (result == JOptionPane.OK_OPTION) {
                panel.updateChartProperties(jFreeChart);
            }
        }

    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void chartChanged(ChartChangeEvent event) {
    try {/*from  w  w  w.  j a va  2 s  . c  o m*/
        if (event.getChart() == null) {
            return;
        }

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            XYPlot hvp = (XYPlot) plot;
            ValueAxis xAxis = hvp.getDomainAxis();
            Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            int low = (int) (xAxisRange.getLowerBound() * scrollFactor);
            scrollBarModel.setValue(low);
            int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            Range hdr = hvp.getDataRange(xAxis);

            double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax;
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        chartPanButton.setEnabled(chartIsZoomed);
        chartZoomOutButton.setEnabled(chartIsZoomed);
        chartFitButton.setEnabled(chartIsZoomed);
        chartScrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            chartZoomButton.setSelected(true);
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:org.zaproxy.zap.extension.ascan.ScanProgressDialog.java

private JFreeChart createChart(final XYDataset dataset) {
    JFreeChart result = ChartFactory.createTimeSeriesChart(null, // No title - it just takes up space 
            Constant.messages.getString("ascan.progress.chart.time"),
            Constant.messages.getString("ascan.progress.chart.responses"), dataset, true, true, false);
    XYPlot plot = result.getXYPlot();
    ValueAxis daxis = plot.getDomainAxis();
    daxis.setAutoRange(true);/*from   w  w w. ja va 2s . co m*/
    daxis.setAutoRangeMinimumSize(60000.0);

    plot.getRangeAxis().setAutoRangeMinimumSize(20);

    return result;
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Translates mouse coordinates to chart coordinates (xy-axis)
 * //from  w  w w  . j  a va 2s .c  o  m
 * @param myChart
 * @param mouseX
 * @param mouseY
 * @return Range as chart coordinates (never null)
 */
public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) {
    XYPlot plot = null;
    // find plot as parent of axis
    ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY);
    if (entity instanceof AxisEntity) {
        Axis a = ((AxisEntity) entity).getAxis();
        if (a.getPlot() instanceof XYPlot)
            plot = (XYPlot) a.getPlot();
    }

    ChartRenderingInfo info = myChart.getRenderingInfo();
    int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    if (subplot != -1)
        dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();

    // find subplot or plot
    if (plot == null)
        plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY);

    // coordinates
    double cx = 0;
    double cy = 0;
    if (plot != null) {
        // find axis
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();
        RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
        // parent?
        if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            domainAxis = pp.getDomainAxis();
            domainAxisEdge = pp.getDomainAxisEdge();
        }
        if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            rangeAxis = pp.getRangeAxis();
            rangeAxisEdge = pp.getRangeAxisEdge();
        }

        if (domainAxis != null)
            cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge);
        if (rangeAxis != null)
            cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge);
    }
    return new Point2D.Double(cx, cy);
}

From source file:org.ow2.clif.jenkins.chart.CallChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(this.eventSerie);

    JFreeChart chart;/*  w  ww . j  a v a 2  s . co  m*/
    if (this.scatterPlot) {
        chart = ChartFactory.createScatterPlot(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                Messages.CallChart_ResponseTime(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createXYLineChart(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                this.chartId.getEvent(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
    }

    chart.setBackgroundPaint(Color.white);
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    Shape cross = ShapeUtilities.createDiamond(3);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShape(cross);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, cross);
    plot.setRenderer(renderer);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);
    return chart;
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java

private synchronized JFreeChart createChart() {
    initSummaries(this.portfolioManagementJPanel);

    final XYDataset priceData = this.createInvestDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(" ",
            GUIBundle.getString("InvestmentFlowChartJDialog_Date"),
            GUIBundle.getString("InvestmentFlowChartJDialog_Value"), priceData, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*from w  w  w .ja v a2  s  .c  o  m*/

    XYPlot plot = chart.getXYPlot();

    NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    final JStockOptions jStockOptions = JStock.instance().getJStockOptions();
    final String currencySymbol = jStockOptions.getCurrencySymbol(jStockOptions.getCountry());
    // Use apostrophes to escape currencySymbol. If currencySymbol contains
    // apostrophes, we may need to escape those by doubling them.
    //
    // 0 decimal place, to save up some display area.
    final NumberFormat currencyFormat = new DecimalFormat("'" + currencySymbol.replace("'", "''") + "'#,##0");
    rangeAxis1.setNumberFormatOverride(currencyFormat);

    plot.setRenderer(1, new StandardXYItemRenderer());
    this.ROITimeSeries = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_ReturnOfInvestment"));
    plot.setDataset(1, new TimeSeriesCollection(this.ROITimeSeries));
    this.updateROITimeSeries();

    return chart;
}

From source file:required.ChartPlotter.java

/**
 * Creates a chart./*from www  . j  a  v a 2 s  . c om*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Zipf's LAW", // chart title
            "frequency", // x axis label
            "words", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}