Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

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

/**
 * Zoom in (negative yzoom) or zoom out of range axis.
 * //from w  ww .j  a v a2s. com
 * @param myChart
 * @param yzoom percentage zoom factor
 * @param holdLowerBound if true only the upper bound will be zoomed
 */
public static void zoomRangeAxis(JFreeChart myChart, double yzoom, boolean holdLowerBound) {
    zoomAxis(myChart.getXYPlot().getRangeAxis(), yzoom, holdLowerBound);
}

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

public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
    XYSeriesCollection xydata = new XYSeriesCollection(series);
    XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
    JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot xyplot = chart.getXYPlot();
    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    xyplot.setForegroundAlpha(0.7F);/* w  w w . jav  a  2  s. c  om*/
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    xybarrenderer.setDrawBarOutline(false);
    return chart;
}

From source file:max.hubbard.Factoring.Graphing.java

private static JFreeChart createChart(final XYDataset dataset, String equation) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(equation, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  w  w w.  jav  a  2 s.co  m*/

    // 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, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(-50, 50));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:ec.util.chart.swing.Charts.java

/**
 * A sparkline is a type of information graphic characterized by its small
 * size and high data density. Sparklines present trends and variations
 * associated with some measurement, such as average temperature or stock
 * market activity, in a simple and condensed way. Several sparklines are
 * often used together as elements of a small multiple.<br>
 *
 * {@link http://en.wikipedia.org/wiki/Sparkline}
 *
 * @param dataset/*w w  w  .j a  va  2 s. c o  m*/
 * @return
 * @author Philippe Charles
 */
@Nonnull
public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) {
    JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    result.setBorderVisible(false);
    result.setBackgroundPaint(null);
    result.setAntiAlias(true);
    XYPlot plot = result.getXYPlot();
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    plot.setBackgroundPaint(null);
    ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false);
    return result;
}

From source file:net.bioclipse.chart.ChartUtils.java

public static void handleCellChangeEvent(CellChangedEvent e) {
    //      Iterator<CellChangeListener> iterator = listeners.iterator();
    //      while( iterator.hasNext() )
    //      {//from  w ww. j a v  a2s. co  m
    //         CellChangeListener listener = iterator.next();
    //         listener.handleCellChangeEvent(e);
    //      }
    Set<JFreeChart> keySet = chartManager.keySet();
    Iterator<JFreeChart> iterator = keySet.iterator();
    while (iterator.hasNext()) {
        JFreeChart chart = iterator.next();

        ChartDescriptor desc = chartManager.get(chart);

        String domainLabel = desc.getXLabel();
        String rangeLabel = desc.getYLabel();
        CellData data = e.getCellData();

        if (domainLabel.equals(data.getColName()) || rangeLabel.equals(data.getColName())) {
            DefaultXYDataset dataset = (DefaultXYDataset) chart.getXYPlot().getDataset();
            int itemCount = dataset.getItemCount(0);
            double[] yValues = new double[itemCount];
            double[] xValues = new double[itemCount];
            for (int i = 0; i < itemCount; i++) {
                double x = dataset.getXValue(0, i);
                double y = dataset.getYValue(0, i);
                xValues[i] = x;
                yValues[i] = y;
            }
            int indices[] = desc.getSourceIndices();
            if (domainLabel.equals(e.getCellData().getColName())) {
                int rowIndex = data.getRowIndex();
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] == rowIndex) {
                        xValues[i] = data.getValue();
                    }
                }
            } else if (rangeLabel.equals(e.getCellData().getColName())) {
                int rowIndex = data.getRowIndex();
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] == rowIndex) {
                        yValues[i] = data.getValue();
                    }
                }
            }
            double[][] chartData = new double[2][];
            chartData[0] = xValues;
            chartData[1] = yValues;

            dataset.getSeriesKey(0);
            Comparable seriesKey = dataset.getSeriesKey(0);

            dataset.removeSeries(seriesKey);
            dataset.addSeries(seriesKey, chartData);
        }
    }
}

From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java

private static ChartPanel getHistogramPlotPanel(XIntervalSeriesCollection dataset, String xAxisLabel,
        String yAxisLabel, Color color) {
    JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, // Legend?
            true, // tooltips
            false // url
    );//  w w w  . j  a v  a 2  s.co  m
    final XYPlot xyPlot = chart.getXYPlot();
    //xyPlot.setForegroundAlpha(0.85f);
    xyPlot.setNoDataMessage("No data");
    xyPlot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    renderer.setSeriesPaint(0, color);
    StandardXYBarPainter painter = new StandardXYBarPainter();
    renderer.setBarPainter(painter);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(300, 200));
    //        chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem());
    return chartPanel;
}

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

public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min, double max) {
    if (data != null && data.length > 0) {
        HistogramDataset dataset = new HistogramDataset();
        dataset.addSeries("histo", data, bin, min, max);

        JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset, PlotOrientation.VERTICAL,
                true, false, false);/*from   w  w  w .j  a v a2  s.  c om*/

        chart.setBackgroundPaint(new Color(230, 230, 230));
        chart.getLegend().setVisible(false);
        XYPlot xyplot = chart.getXYPlot();
        xyplot.setForegroundAlpha(0.7F);
        xyplot.setBackgroundPaint(Color.WHITE);
        xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
        xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
        xyplot.getDomainAxis().setVisible(true);
        xyplot.getRangeAxis().setVisible(yAxisLabel != null);
        XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
        xybarrenderer.setShadowVisible(false);
        xybarrenderer.setBarPainter(new StandardXYBarPainter());
        // xybarrenderer.setDrawBarOutline(false);
        return chart;
    } else
        return null;
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

public static JFreeChart createBlockingBarChart(String title, HistogramDataset dataset) {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart chart = ChartFactory.createHistogram(null, title, "Key frequency", dataset, //$NON-NLS-1$
            PlotOrientation.VERTICAL, false, true, false);

    XYPlot plot = chart.getXYPlot();
    plot.getRangeAxis().setUpperMargin(0.08);
    // plot.getRangeAxis().setLowerBound(-0.08);
    decorateCategoryPlot(chart);//from  w  w w .j av a  2 s . c o m
    plot.setRangeGridlinesVisible(true);

    XYBarRenderer renderer = new XYBarRenderer() {

        private static final long serialVersionUID = 4168794048090452033L;

        @Override
        public Paint getItemPaint(int row, int column) {
            return ChartDecorator.COLOR_LIST.get(0);
        }
    };
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setBaseNegativeItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setShadowVisible(Boolean.FALSE);
    plot.setRenderer(renderer);

    return chart;
}

From source file:com.joey.software.plottingToolkit.PlotingToolkit.java

/**
 * This will plot the data as series of data[1], data[2], data[3]....
 * /*from  ww w .  j  a  v a 2 s .co  m*/
 * @param data
 * @param names
 * @param title
 * @param xlabel
 * @param ylabel
 * @return
 */
public static JFreeChart getPlot(float[][] data, String[] names, String title, String xlabel, String ylabel,
        boolean showPoints, boolean showLines) {

    // Create the chart

    JFreeChart chart = ChartFactory.createXYLineChart(title, // Title
            xlabel, // X-Axis label
            ylabel, // Y-Axis label
            new XYSeriesCollection(), // Dataset
            PlotOrientation.VERTICAL, true, // Show legend
            true, true);

    for (int i = 0; i < data.length; i++) {
        float[] xData = getXDataFloat(data[i].length);
        XYSeriesCollection datCol = getCollection(xData, data[i],
                ((names == null) || (names[i] == null) ? "" : names[i]));

        // Add the series
        chart.getXYPlot().setDataset(i, datCol);

        // Set the rendering
        XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(showLines, showPoints);
        rend1.setSeriesPaint(0, getPlotColor(i));
        chart.getXYPlot().setRenderer(i, rend1);
    }
    return chart;
}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param adapter/*from   w  w w .j  a  v a2 s.c  o m*/
 * @param annotations
 * @return
 */
private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) {

    final JFreeChart chart;
    if (adapter.getItems() instanceof XYDataset) {

        chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (XYDataset) adapter.getItems(), true, false, false);
        final ValueAxis domainAxis = new DateAxis();
        domainAxis.setLabelFont(LABEL_FONT);
        domainAxis.setTickLabelFont(LABEL_FONT);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);

        chart.getXYPlot().setDomainAxis(domainAxis);
        chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits());

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.2));
            chart.getXYPlot().getRangeAxis().setRange(range);
        }

        for (Marker marker : adapter.getMarkers()) {
            chart.getXYPlot().addDomainMarker(marker);
        }

        if (annotations != null) {
            for (XYAnnotation annotation : annotations) {
                if (annotation instanceof XYPointerAnnotation) {
                    ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT);
                }
                chart.getXYPlot().addAnnotation(annotation);
            }
        }

        // Add any bands to the chart
        if (adapter instanceof TimeSeriesChart) {
            final TimeSeriesChart tsc = (TimeSeriesChart) adapter;
            for (int i = 0; i < tsc.getBands().size(); i++) {

                final Color c = tsc.getBandColors().get(i);
                final Color fill = tsc.getBandFillColors().get(i);
                final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false);
                renderer.setSeriesPaint(0, c);
                renderer.setSeriesPaint(1, c);
                renderer.setSeriesStroke(0, LineStyle.THICK.getStroke());
                renderer.setSeriesStroke(1, LineStyle.THICK.getStroke());

                chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i));
                chart.getXYPlot().setRenderer(i + 1, renderer);
            }
        }

    } else if (adapter.getItems() instanceof CategoryDataset) {

        chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false);
        chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.1));
            chart.getCategoryPlot().getRangeAxis().setRange(range);
        }

    } else {
        throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass());
    }

    chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE);

    return chart;
}