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:scrum.server.common.BurndownChart.java

private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay,
        Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit,
        float widthPerDay) {
    DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay,
            freeDays);/*ww  w.  java2  s.  c o  m*/

    double tick = 1.0;
    double max = BurndownChart.getMaximum(data);

    while (max / tick > 25) {
        tick *= 2;
        if (max / tick <= 25)
            break;
        tick *= 2.5;
        if (max / tick <= 25)
            break;
        tick *= 2;
    }
    double valueLabelTickUnit = tick;
    double upperBoundary = Math.min(max * 1.1f, max + 3);

    if (!Sys.isHeadless())
        LOG.warn("GraphicsEnvironment is not headless");
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true,
            false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = chart.getXYPlot();
    // plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // plot.setOutlineVisible(false);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);
    // plot.setRangeCrosshairPaint(Color.lightGray);
    // plot.setRangeMinorGridlinePaint(Color.lightGray);
    // plot.setDomainCrosshairPaint(Color.blue);
    // plot.setDomainMinorGridlinePaint(Color.green);
    // plot.setDomainTickBandPaint(Color.green);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2f));

    renderer.setSeriesPaint(0, COLOR_PAST_LINE);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE);
    renderer.setSeriesStroke(1,
            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0));
    renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE);
    renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    DateAxis domainAxis1 = new DateAxis();
    String dateFormat = "d.";
    widthPerDay -= 5;
    if (widthPerDay > 40) {
        dateFormat = "EE " + dateFormat;
    }
    if (widthPerDay > 10) {
        float spaces = widthPerDay / 2.7f;
        dateFormat = Str.multiply(" ", (int) spaces) + dateFormat;
    }
    domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US));
    domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit));
    domainAxis1.setAxisLineVisible(false);
    Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis());
    domainAxis1.setRange(range);

    DateAxis domainAxis2 = new DateAxis();
    domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    domainAxis2.setTickMarksVisible(false);
    domainAxis2.setTickLabelsVisible(false);
    domainAxis2.setRange(range);

    plot.setDomainAxis(0, domainAxis2);
    plot.setDomainAxis(1, domainAxis1);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit));

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(upperBoundary);

    plot.setRangeAxis(rangeAxis);

    return chart;
}

From source file:playground.johannes.socialnets.GraphStatistics.java

public static JFreeChart makeChart(Histogram1D hist, String title) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    for (int i = 0; i < 100; i++) {
        wave.add(hist.xAxis().binCentre(i), hist.binHeight(i));
    }//from  ww  w. j  a  v  a2s  . c  om

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    return chart;
}

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

public static JFreeChart getPlot(double[] xData, double[] yData, String title, String xlabel, String ylabel) {

    XYSeriesCollection datCol = getCollection(xData, yData, "Data");

    // 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);/*from w  ww  . java  2s  .  co  m*/

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

    // Set the rendering
    XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(true, true);
    rend1.setShapesVisible(false);
    chart.getXYPlot().setRenderer(0, rend1);

    return chart;
}

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

public static JFreeChart getPlot(double[] yData, String title, String xlabel, String ylabel) {
    double[] xData = getXDataDouble(yData.length);
    XYSeriesCollection datCol = getCollection(xData, yData, "Data");

    // 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);/* w w w. j  a v  a2s.  co m*/

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

    // Set the rendering
    XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(true, true);

    chart.getXYPlot().setRenderer(0, rend1);

    return chart;
}

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

public static JFreeChart getPlot(float[] yData, String title, String xlabel, String ylabel) {
    float[] xData = getXDataFloat(yData.length);
    XYSeriesCollection datCol = getCollection(xData, yData, "Data");

    // 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);/*  w w  w. j  ava2 s . com*/

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

    // Set the rendering
    XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(true, true);

    chart.getXYPlot().setRenderer(0, rend1);

    return chart;
}

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

public static JFreeChart getPlot(int[] xData, int[] yData, String title, String xlabel, String ylabel) {

    XYSeriesCollection datCol = getCollection(xData, yData, "Data");

    // 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);/*from  w  w w  .j  a v a  2 s  . c  om*/

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

    // Set the rendering
    XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(true, true);

    chart.getXYPlot().setRenderer(0, rend1);

    return chart;
}

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

/**
 * Extracts the visualized data from a given chart instance.
 * <p>//from w w  w  .ja va 2  s.  co  m
 * This methods extracts the default data series from the default dataset of the given chart.
 * </p>
 * 
 * @param aChart
 *            Chart to extract the data from.
 * @return Visualized data in the form of an array of points.
 */
public static Point2D.Double[] extractData(JFreeChart aChart) {
    XYDataset dataColl = aChart.getXYPlot().getDataset();
    final int n = dataColl.getItemCount(0);
    Point2D.Double[] dataPoints = new Point2D.Double[n];
    for (int i = 0; i < n; ++i) {
        dataPoints[i] = new Point2D.Double(dataColl.getXValue(0, i), dataColl.getYValue(0, i));
    }
    return dataPoints;
}

From source file:utils.Graficos_old.java

public static JFreeChart GraficoLinhas(List<CarCapContas> pagar, List<CarCapContas> receber, String titulo) {

    XYSeries series1 = new XYSeries("Pagar");

    //        CarCapContas contasPagar = new CarCapContas();
    for (CarCapContas contasPagar : pagar) {

        series1.add(contasPagar.getContaValorTotal(), contasPagar.getContaDataEmissao().getMonth());

    }/* w  w  w .j a v  a 2 s . c  o m*/

    XYSeries series2 = new XYSeries("Receber");

    for (CarCapContas contasReceber : receber) {

        series2.add(contasReceber.getContaValorTotal(), contasReceber.getContaDataEmissao().getMonth());

    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(series1);
    dataset.addSeries(series2);

    JFreeChart chart = ChartFactory.createXYLineChart(titulo, // 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);

    // 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.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the bar properties of a chart.
 * /*  w  ww .j  a va  2s  .com*/
 * @param aControl
 *            Chart control to be updated.
 * @param aBars
 *            Bar visual settings to be applied.
 */
public static void updateBars(JFreeChart aControl, BarsSettings aBars) {
    updateBars(aControl.getXYPlot(), aBars);
}

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

private static JFreeChart chartProfile(int length, TimeSeriesCollection dataset, String descriptor,
        String yax) {/* ww  w.  java  2 s  .  co  m*/
    JFreeChart chart = ChartFactory.createTimeSeriesChart(descriptor, "Time", yax, dataset);

    // ChartFactory.createXYLineChart("TimeProfile", "Time", "Wait Time
    // [s]", dataset,
    // PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRange(true);

    XYItemRenderer renderer = plot.getRenderer();
    for (int s = 0; s < length; s++) {
        renderer.setSeriesStroke(s, new BasicStroke(2));
    }

    return chart;
}