Example usage for org.jfree.chart.axis DateAxis setUpperMargin

List of usage examples for org.jfree.chart.axis DateAxis setUpperMargin

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateAxis setUpperMargin.

Prototype

public void setUpperMargin(double margin) 

Source Link

Document

Sets the upper margin for the axis (as a percentage of the axis range) and sends an AxisChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {

    DateAxis timeAxis = new DateAxis(xAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }/*w  w  w .jav a2  s  . c  om*/

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    //        renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);

    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

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

private static JFreeChart createTimeSeriesChart2(XYDataset dataset) {

    DateAxis timeAxis = new DateAxis(xAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }/*from   w w w  .  j  a va  2s.  co  m*/

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);

    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

From source file:y.graphs.ChartHelperSRB.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );/*w  ww. j a  va2s  .  c o m*/

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundSRB());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //          renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //      rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:y.graphs.ChartHelperELF.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );/*from   www  . ja  v  a 2s .co m*/

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundELF());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //            renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //        rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

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);/*  w  w w. j  ava 2  s.co  m*/
    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.operamasks.faces.render.graph.AreaChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;/*from  w ww .j a v  a2  s  . c o m*/

    if (dataset instanceof CategoryDataset) {
        if (comp.isStacked()) {
            chart = ChartFactory.createStackedAreaChart(null, null, null, (CategoryDataset) dataset,
                    getChartOrientation(comp), false, false, false);
        } else {
            chart = ChartFactory.createAreaChart(null, null, null, (CategoryDataset) dataset,
                    getChartOrientation(comp), false, false, false);
        }
    } else if (dataset instanceof XYDataset) {
        chart = ChartFactory.createXYAreaChart(null, null, null, (XYDataset) dataset, getChartOrientation(comp),
                false, false, false);

        if (dataset instanceof TimeSeriesCollection) {
            DateAxis xAxis = new DateAxis(null);
            xAxis.setLowerMargin(0.02);
            xAxis.setUpperMargin(0.02);
            ((XYPlot) chart.getPlot()).setDomainAxis(xAxis);
        }
    }

    return chart;
}

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

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

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelInsets(new RectangleInsets(2, 5, 2, 5));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setLowerMargin(0.02);/*from  w  w  w  .  ja va  2 s.  co  m*/
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

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

    return result;
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.JVMView.java

private JFreeChart createHeapChart(double maxMemory) {
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    dataSet.addSeries(memoryUsageSeries);
    dataSet.addSeries(heapSizeSeries);/*from  w w  w.j  a va 2s  .c  o m*/
    JFreeChart chart = ChartFactory.createXYAreaChart("JVM Heap", "Time", "Megabytes", dataSet,
            PlotOrientation.VERTICAL, true, // Legend.
            false, // Tooltips.
            false);
    DateAxis timeAxis = new DateAxis("Time");
    timeAxis.setLowerMargin(0);
    timeAxis.setUpperMargin(0);
    chart.getXYPlot().setDomainAxis(timeAxis);
    chart.getXYPlot().getRangeAxis().setLowerBound(0);
    chart.getXYPlot().getRangeAxis().setUpperBound(maxMemory * 1.1); // Add 10% to leave room for marker.

    // Add a horizontal marker to indicate the heap growth limit.
    ValueMarker marker = new ValueMarker(maxMemory, Color.BLACK, new BasicStroke(1));
    marker.setLabel("Maximum Permitted Heap Size (adjust with -Xmx)");
    marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    marker.setLabelAnchor(RectangleAnchor.RIGHT);
    chart.getXYPlot().addRangeMarker(marker);

    chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.RED);
    chart.getXYPlot().getRenderer().setSeriesPaint(1, new Color(0, 128, 0, 128));

    return chart;
}

From source file:org.mustbe.consulo.xprofiler.ui.mainPanel.MemoryPlotPanel.java

public MemoryPlotPanel(int maxAge, String title) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Committed Memory");
    totalSeries.setMaximumItemAge(maxAge);
    usedSeries = new TimeSeries("Used Memory");
    usedSeries.setMaximumItemAge(maxAge);
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);
    seriesCollection.addSeries(usedSeries);

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");

    dateAxis.setAutoRange(true);//  w  ww .  ja v a2  s  . co  m
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, JBColor.RED);
    lineRenderer.setSeriesPaint(1, JBColor.GREEN);
    lineRenderer.setDefaultStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPainter(new ColorPainter(JBColor.white));
    xyplot.setDomainGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPainter(new ColorPainter(JBColor.white));

    add(new ChartPanel(chart, 300, 300, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, false,
            false, false), BorderLayout.CENTER);
}

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

/**
 * Creates a chart./*from   w w w.j a va2  s. c  o m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(final TableXYDataset dataset) {

    final StandardXYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd-MMM-yyyy", Locale.UK),
            NumberFormat.getInstance());
    final DateAxis xAxis = new DateAxis("Domain (X)");
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    final NumberAxis yAxis = new NumberAxis("Range (Y)");
    yAxis.setAutoRangeIncludesZero(true);
    final StackedXYAreaRenderer renderer = new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES,
            toolTipGenerator, null);
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(255, 255, 206));
    renderer.setSeriesPaint(1, new Color(206, 230, 255));
    renderer.setSeriesPaint(2, new Color(255, 230, 230));
    renderer.setShapePaint(Color.gray);
    renderer.setShapeStroke(new BasicStroke(0.5f));
    renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6));
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    return chart;
}