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

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

Introduction

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

Prototype

public void setAxisOffset(RectangleInsets offset) 

Source Link

Document

Sets the axis offsets (gap between the data area and the axes) and sends a PlotChangeEvent to all registered listeners.

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);// w  w  w  . j  a v  a2  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:Data.java

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

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Graphique des tempratures et humidits", // title
            "Date", // x-axis label
            "Temperture/Humidit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("d.M.yy HH:mm:ss"));

    return chart;

}

From source file:org.jfree.chart.demo.DifferenceChartDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Difference Chart Demo 1", "Time", "Value",
            xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYDifferenceRenderer xydifferencerenderer = new XYDifferenceRenderer(Color.green, Color.red, false);
    xydifferencerenderer.setRoundXCoordinates(true);
    xyplot.setDomainCrosshairLockedOnData(true);
    xyplot.setRangeCrosshairLockedOnData(true);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    xyplot.setRenderer(xydifferencerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = new DateAxis("Time");
    dateaxis.setLowerMargin(0.0D);//  w  ww  .  j av  a2  s  .com
    dateaxis.setUpperMargin(0.0D);
    xyplot.setDomainAxis(dateaxis);
    xyplot.setForegroundAlpha(0.5F);
    return jfreechart;
}

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

private static JFreeChart createTsChart() {
    XYPlot plot = new XYPlot();

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setLowerMargin(0.02);//from w  ww. j  a va2s  .c om
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    plot.setRangeAxis(rangeAxis);

    JFreeChart result = new JFreeChart("", null, plot, true);
    result.setPadding(new RectangleInsets(5, 5, 5, 5));
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);

    return result;
}

From source file:org.mwc.debrief.sensorfusion.views.DataSupport.java

/**
 * Creates a chart.//from w w  w .j  av a 2  s  . c o m
 * 
 * @param dataset
 *          a dataset.
 * 
 * @return A chart.
 */
public static JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Bearing Management", // title
            "Time", // x-axis label
            "Bearing", // y-axis label
            dataset, // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    plot.setOrientation(PlotOrientation.HORIZONTAL);

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm.ss"));

    return chart;

}

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

/**
 * This function is used for the visualization of two Area Diagrams.
 * //  www  .j  a  v  a  2  s .  co  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 doubles
 *          The array of values of the first array.
 * 
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createExpectedPowerChart(String title, String x, String y, double[] data) {
    JFreeChart chart = null;

    XYSeries series1 = new XYSeries("Expected Power");
    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);
    }

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

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

    chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setRange(0.0, 1440.0);
    domainAxis.setTickUnit(new NumberTickUnit(100));

    return new ChartPanel(chart);
}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static JFreeChart createTimeSeriesChart() {
    XYDataset dataset1 = createDataset1();
    //DomainAxis// w ww  . j a  v a  2 s  .c om
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    NumberAxis valueAxis2 = new NumberAxis("");
    valueAxis2.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    XYDataset dataset2 = createDataset2();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    //Plot
    XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, valueAxis2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setBackgroundPaint(plotBackgroundPaint);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    valueAxis.setAutoRange(false);
    timeAxis.setAutoRange(false);
    return chart;
}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerAndPredictionDifference.java

private static JFreeChart createChart() {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(NAME, "Power (Watts)", "Power (Watts)", data,
            true, true, false);// ww  w .  j a va 2 s.  c  o  m
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYDifferenceRenderer xydifferencerenderer = new XYDifferenceRenderer(Color.green, Color.yellow, false);
    xydifferencerenderer.setRoundXCoordinates(true);
    xyplot.setDomainCrosshairLockedOnData(true);
    xyplot.setRangeCrosshairLockedOnData(true);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    xyplot.setRenderer(xydifferencerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = new DateAxis("Samples");
    dateaxis.setTickLabelsVisible(false);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    xyplot.setDomainAxis(dateaxis);
    xyplot.setForegroundAlpha(0.5F);
    return jfreechart;
}

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
    );//from   ww w . ja v a 2  s  .c  om
    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:ioheater.ui.IOHeaterUI.java

/**
 * Creates a chart.//w w w  . ja  v  a  2 s.  c  o  m
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Temperature Trend", // title
            "Time (m:s)", // x-axis label
            "Temperature (C)", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("H:mm:ss"));

    return chart;
}