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:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC bZhou Comment method "decorateXYPlot".
 * //from  w  ww. j  a  va 2 s .  co m
 * @param chart
 */
private static void decorateXYPlot(JFreeChart chart) {

    Font font = null;
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer render = plot.getRenderer();
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis valueAxis = plot.getRangeAxis();

    font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$

    render.setBaseItemLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    valueAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);

    setLegendFont(chart);

    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }

    font = null;
}

From source file:org.gumtree.vis.awt.PlotFactory.java

public static JFreeChart createXYErrorChart(IXYErrorDataset dataset) {

    JFreeChart chart;//from  w  ww.j av a  2  s  .  c o  m
    String title = null;
    String xTitle = null;
    String yTitle = null;
    if (dataset != null) {
        title = "";
        if (dataset.getTitle() != null) {
            title = dataset.getTitle();
        }
        xTitle = "";
        if (dataset.getXTitle() != null) {
            xTitle += dataset.getXTitle();
        }
        if (dataset.getXUnits() != null) {
            xTitle += " (" + dataset.getXUnits() + ")";
        }
        yTitle = "";
        if (dataset.getYTitle() != null) {
            yTitle += dataset.getYTitle();
        }
        if (dataset.getYUnits() != null) {
            yTitle += " (" + dataset.getYUnits() + ")";
        }
    } else {
        dataset = new XYErrorDataset();
    }
    chart = createXYLineChart(title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, false, true);
    chart.setBackgroundPaint(Color.WHITE);
    final LegendTitle legend = (LegendTitle) chart.getLegend();
    RectangleEdge legendPosition = RectangleEdge.BOTTOM;
    try {
        String legendProperty = "RectangleEdge." + System.getProperty("kuranda1D.legendPosition");
        if (RectangleEdge.BOTTOM.toString().equals(legendProperty))
            legendPosition = RectangleEdge.BOTTOM;
        else if (RectangleEdge.RIGHT.toString().equals(legendProperty))
            legendPosition = RectangleEdge.RIGHT;
        else if (RectangleEdge.LEFT.toString().equals(legendProperty))
            legendPosition = RectangleEdge.LEFT;
        else if (RectangleEdge.TOP.toString().equals(legendProperty))
            legendPosition = RectangleEdge.TOP;
    } catch (Exception e) {
        // TODO: handle exception
    }
    legend.setPosition(legendPosition);
    chart.setBorderVisible(true);
    //      ChartUtilities.applyCurrentTheme(chart);
    //      chartTheme.apply(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    //      plot.setRangeZeroBaselineVisible(false);
    //      plot.setDomainZeroBaselineVisible(false);
    ValueAxis rangeAxis = plot.getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        ((NumberAxis) rangeAxis).setAutoRangeStickyZero(false);
        ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(false);
    }
    ValueAxis domainAxis = plot.getDomainAxis();
    if (domainAxis instanceof NumberAxis) {
        ((NumberAxis) domainAxis).setAutoRangeStickyZero(false);
        ((NumberAxis) domainAxis).setAutoRangeIncludesZero(false);
    }
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setDomainGridlinesVisible(true);
    //        plot.setDomainCrosshairLockedOnData(true);
    //        plot.setDomainCrosshairVisible(true);
    plot.setRangeGridlinesVisible(true);
    //        plot.setRangeCrosshairLockedOnData(true);
    //        plot.setRangeCrosshairVisible(true);

    //      xAxis = plot.getDomainAxis();
    //        yAxis = plot.getRangeAxis();

    plot.setDataset(dataset);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    if (renderer instanceof XYErrorRenderer) {
        //         ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(true);
        ((XYErrorRenderer) renderer).setBaseShapesFilled(true);
        ((XYErrorRenderer) renderer).setDrawXError(false);
        ((XYErrorRenderer) renderer).setDrawYError(true);
    }

    chart.fireChartChanged();
    return chart;
}

From source file:org.matsim.contrib.drt.analysis.DensityScatterPlots.java

public static JFreeChart createPlot(String title, String xAxisLabel, String yAxisLabel, XYSeries series,
        Pair<Double, Double> lineCoeffs) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);//from w  w  w.  j  av a2s . co m
    double maxValue = Math.max(series.getMaxX(), series.getMaxY());

    // y=x
    XYSeries lineXY = new XYSeries("y = x");
    lineXY.add(0, 0);
    lineXY.add(maxValue, maxValue);
    dataset.addSeries(lineXY);

    if (lineCoeffs != null) {
        // a*y+b=x
        double a = lineCoeffs.getLeft();
        double b = lineCoeffs.getRight();
        String namePrefix = a == 0 ? "" : (a + " * y + ");
        XYSeries lineABXY = new XYSeries(namePrefix + b + " = x");
        lineABXY.add(b, 0);
        if (a == 0) {
            lineABXY.add(b, maxValue);
        } else {
            lineABXY.add(maxValue, (maxValue - b) / a);
        }
        dataset.addSeries(lineABXY);
    }

    final JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset);
    XYPlot xyPlot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(0);
    renderer.setSeriesPaint(0, new Color(255, 0, 0, 50));
    renderer.setSeriesShape(0, CIRCLE);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesVisibleInLegend(0, false);

    for (int i = 1; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesPaint(i, new Color(0, 0, 0));
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesVisibleInLegend(i, false);
    }

    xyPlot.getDomainAxis().setUpperBound(maxValue);
    xyPlot.getRangeAxis().setUpperBound(maxValue);
    xyPlot.getDomainAxis().setLowerBound(0);
    xyPlot.getRangeAxis().setLowerBound(0);

    return chart;
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Comparative Response Model
 * Histogram./*from ww w.j  a va2  s  .c  o  m*/
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param dataBefore
 *          The array of values before the response.
 * @param dataAfter
 *          The array of values after the response.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createResponseHistogram(String title, String x, String y, double[] dataBefore,
        double[] dataAfter) {
    XYSeries series1 = new XYSeries("Basic Pricing Scheme");
    for (int i = 0; i < dataBefore.length; i++) {
        series1.add(i, dataBefore[i]);
    }

    XYSeries series2 = new XYSeries("New Pricing Scheme");
    for (int i = 0; i < dataAfter.length; i++) {
        series2.add(i, dataAfter[i]);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = true;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);
    xyplot.setForegroundAlpha(0.85F);
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    // domainAxis.setRange(0.0, 1440.0);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickUnit(new NumberTickUnit(0.1));

    return new ChartPanel(chart);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Creates a histogram chart that displays the given long histogram data.
 * /*from   w w w .  ja  va2  s . c  om*/
 * @param aHistogram
 *            Complex parameter that stores the data to be visualized.
 * @param aSettings
 *            Settings group for long histogram.
 * @return Newly created chart control.
 */
public static JFreeChart createHistogram(LongHistogram aHistogram, LongHistogramGroup aSettings) {
    XYSeriesCollection collection = fromLongHistogram(aHistogram);
    JFreeChart chart = ChartFactory.createHistogram(null, // title
            convertLabel(aSettings.axes.getDomainAxisLabel()), // label of X axis
            convertLabel(aSettings.axes.getRangeAxisLabel()), // label of Y axis
            collection, // dataset
            PlotOrientation.VERTICAL, // orientation
            false, // create legend
            false, // display tooltips
            false); // generate urls
    XYPlot plot = chart.getXYPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    updateGeneral(plot, aSettings.general);
    updateAxes(chart, aSettings.axes, aSettings.grid);
    updateBars(plot, aSettings.bars);
    chart.setBackgroundPaint(null);
    return chart;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Creates a histogram chart that displays the given integer histogram data.
 * /*  w w  w.  ja va  2 s .  c om*/
 * @param aHistogram
 *            Complex parameter that stores the data to be visualized.
 * @param aSettings
 *            Settings group for integer histogram.
 * @return Newly created chart control.
 */
public static JFreeChart createHistogram(IntHistogram aHistogram, IntHistogramGroup aSettings) {

    XYSeriesCollection collection = fromIntHistogram(aHistogram);
    JFreeChart chart = ChartFactory.createHistogram(null, // title
            convertLabel(aSettings.axes.getDomainAxisLabel()), // label of X axis
            convertLabel(aSettings.axes.getRangeAxisLabel()), // label of Y axis
            collection, // dataset
            PlotOrientation.VERTICAL, // orientation
            false, // create legend
            false, // display tooltips
            false); // generate urls
    XYPlot plot = chart.getXYPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    updateGeneral(plot, aSettings.general);
    updateAxes(chart, aSettings.axes, aSettings.grid);
    updateBars(plot, aSettings.bars);
    chart.setBackgroundPaint(null);
    return chart;
}

From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java

/**
 * Creates a chart.//from w ww .  j  a  v  a  2 s  .  com
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", // title
            null, // x-axis label
            "US cents/lb", // y-axis label
            dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf",
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * This is a helper method for creating a line chart. This should only do
 * the chart creation and not setting up the dataset. The calling method
 * should do the logic for the dataset setup.
 * @param c //  ww w.  j a v  a 2s .c  o  m
 * 
 * @param xyCollection
 *            The dataset to display a chart for.
 * @param chartType
 *            The chart type. This must be a valid chart type that can be
 *            created from an XY dataset. At current only line and scatter
 *            are supported
 * @param legendPosition
 *            The position of the legend.
 * @param chartName
 *            The name of the chart.
 * @param yaxisName
 *            The name of the y axis.
 * @param xaxisName
 *            The name of the x axis.
 * @return A chart of the specified chartType based on the given dataset.
 */
private static JFreeChart createChartFromXYDataset(Chart c, XYDataset xyCollection, ChartType chartType,
        LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) {
    boolean showLegend = !legendPosition.equals(LegendPosition.NONE);
    JFreeChart chart;
    if (chartType.equals(ChartType.LINE)) {
        chart = ChartFactory.createXYLineChart(chartName, xaxisName, yaxisName, xyCollection,
                PlotOrientation.VERTICAL, showLegend, true, false);
    } else if (chartType.equals(ChartType.SCATTER)) {
        chart = ChartFactory.createScatterPlot(chartName, xaxisName, yaxisName, xyCollection,
                PlotOrientation.VERTICAL, showLegend, true, false);
    } else {
        throw new IllegalArgumentException("Unknown chart type " + chartType + " for an XY dataset.");
    }
    if (chart == null)
        return null;
    XYPlot plot = (XYPlot) chart.getPlot();

    // XXX the following instance check is brittle; there are many ways to represent a time
    // series in JFreeChart. This check uses knowledge of the inner workings of DatasetUtil.
    if (xyCollection instanceof TimePeriodValuesCollection) {
        logger.debug("Switching x-axis to date axis so labels render properly");
        plot.setDomainAxis(new DateAxis(xaxisName));
        // TODO user-settable date format
        // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    }

    if (legendPosition != LegendPosition.NONE) {
        chart.getLegend().setPosition(legendPosition.getRectangleEdge());
    }

    if (!c.isAutoXAxisRange()) {
        XYPlot xyplot = chart.getXYPlot();
        ValueAxis axis = xyplot.getDomainAxis();
        axis.setAutoRange(false);
        axis.setRange(c.getXAxisMinRange(), c.getXAxisMaxRange());
    }
    if (!c.isAutoYAxisRange()) {
        XYPlot xyplot = chart.getXYPlot();
        ValueAxis axis = xyplot.getRangeAxis();
        axis.setAutoRange(false);
        axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange());
    }

    return chart;
}

From source file:logica.LGraficapeso.java

public static void logicaBtnGraficar(JRadioButton jRLinea) {

    ChartPanel panel;// w ww  .  j a v  a  2 s.  com
    JFreeChart chart = null;

    if (jRLinea.isSelected()) {
        // ejecuto linea

        XYSplineRenderer graficoLinea = new XYSplineRenderer();

        XYSeriesCollection dataset = new XYSeriesCollection();

        ValueAxis x = new NumberAxis();
        ValueAxis y = new NumberAxis();

        XYSeries serie = new XYSeries("Datos");

        XYPlot plot;

        graficoLinea.setSeriesPaint(0, Color.YELLOW);

        VGraficaPeso.getPanelLinea().removeAll();

        for (int i = 0; i < VGraficaPeso.getjTable1().getRowCount(); i++) {

            float valor1 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 0)));
            float valor2 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 1)));

            System.out.println("valores  " + valor1 + "   " + valor2);

            serie.add(valor1, valor2);

        }

        dataset.addSeries(serie);

        x.setLabel("MES");
        y.setLabel("peso");

        plot = new XYPlot(dataset, x, y, graficoLinea);

        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setRange(10, 15);

        chart = new JFreeChart(plot);
        chart.setTitle("grafico");

        panel = new ChartPanel(chart);
        panel.setBounds(5, 10, 410, 350);

        VGraficaPeso.getPanelLinea().add(panel);
        VGraficaPeso.getPanelLinea().repaint();

    }

}

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

/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)//from  w ww  .j  a  va 2  s .  c om
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartViewer myChart, double plotWidth, int iterations) {
    // ranges
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    Range y = rangeAxis.getRange();

    // plot height is fixed
    double plotHeight = plotWidth / x.getLength() * y.getLength();
    return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}