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

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

Introduction

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

Prototype

public void setAutoRange(boolean auto) 

Source Link

Document

Sets a flag that determines whether or not the axis range is automatically adjusted to fit the data, and notifies registered listeners that the axis has been modified.

Usage

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
    );//from  ww w. ja v a  2  s  . 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
    );/*w  w  w . j  a  va 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:com.unicornlabs.kabouter.reporting.PowerReport.java

public static void GeneratePowerReport(Date startDate, Date endDate) {
    try {//from   w  w w  .  j av  a 2 s. c o m
        Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName());
        ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds();

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        File outputFile = new File("PowerReport.pdf");
        outputFile.createNewFile();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();

        document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString()));

        document.newPage();

        DecimalFormat df = new DecimalFormat("#.###");

        for (String deviceId : powerLogDeviceIds) {
            ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate);
            double total = 0;
            double max = 0;
            Date maxTime = startDate;
            double average = 0;
            XYSeries series = new XYSeries(deviceId);
            XYDataset dataset = new XYSeriesCollection(series);

            for (Powerlog log : powerlogs) {
                total += log.getPower();
                if (log.getPower() > max) {
                    max = log.getPower();
                    maxTime = log.getId().getLogtime();
                }
                series.add(log.getId().getLogtime().getTime(), log.getPower());
            }

            average = total / powerlogs.size();

            document.add(new Paragraph("\nDevice: " + deviceId));
            document.add(new Paragraph("Average Power Usage: " + df.format(average)));
            document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString()));
            document.add(new Paragraph("Total Power Usage: " + df.format(total)));
            //Create a custom date axis to display dates on the X axis
            DateAxis dateAxis = new DateAxis("Date");
            //Make the labels vertical
            dateAxis.setVerticalTickLabels(true);

            //Create the power axis
            NumberAxis powerAxis = new NumberAxis("Power");

            //Set both axes to auto range for their values
            powerAxis.setAutoRange(true);
            dateAxis.setAutoRange(true);

            //Create the tooltip generator
            StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

            //Set the renderer
            StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg,
                    null);

            //Create the plot
            XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

            //Create the chart
            JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

            PdfContentByte pcb = writer.getDirectContent();
            PdfTemplate tp = pcb.createTemplate(480, 360);
            Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper());
            Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360);
            myChart.draw(g2d, r2d);
            g2d.dispose();
            pcb.addTemplate(tp, 0, 0);

            document.newPage();
        }

        document.close();

        JOptionPane.showMessageDialog(null, "Report Generated.");

        Desktop.getDesktop().open(outputFile);
    } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(null,
                "Unable To Open File For Writing, Make Sure It Is Not Currently Open");
    } catch (IOException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java

private static JFreeChart createChart(final SecurityNode node) {
    Objects.requireNonNull(node);

    final List<SecurityHistoryNode> hNodes = node.getHistoryNodes();
    final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate());
    final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate());

    final DateAxis timeAxis = new DateAxis(null);
    timeAxis.setVisible(false);//from  w w w . ja  v a  2  s  .  co m
    timeAxis.setAutoRange(false);
    timeAxis.setRange(min, max);

    final NumberAxis valueAxis = new NumberAxis(null);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setVisible(false);

    final XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node));
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(225, 247, 223));

    final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer);

    final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits();

    for (int i = 0; i < groups.size(); i++) {
        int size = groups.get(i).size();

        Date[] date = new Date[size];
        double[] high = new double[size];
        double[] low = new double[size];
        double[] open = new double[size];
        double[] close = new double[size];
        double[] volume = new double[size];

        for (int j = 0; j < size; j++) {
            final SecurityHistoryNode hNode = groups.get(i).get(j);

            date[j] = DateUtils.asDate(hNode.getLocalDate());
            high[j] = hNode.getAdjustedHigh().doubleValue();
            low[j] = hNode.getAdjustedLow().doubleValue();
            open[j] = hNode.getAdjustedPrice().doubleValue();
            close[j] = hNode.getAdjustedPrice().doubleValue();
            volume[j] = hNode.getVolume();
        }

        final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low,
                open, close, volume);
        plot.setDataset(i, data);
    }

    plot.setInsets(new RectangleInsets(1, 1, 1, 1));

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

    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);
    dateAxis.setLowerMargin(0);//from   w ww  . j ava 2 s  . co m
    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:uk.co.petertribble.jkstat.demo.JLoadChart.java

/**
 * A standalone demo charting load averages.
 *///from  w  ww  . j  a  va2s  .  c  o m
public JLoadChart() {
    super("JLoadChart");

    jkstat = new NativeJKstat();
    int maxage = 600000;

    String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT");
    ts1 = new TimeSeries("1min " + lavetext);
    ts1.setMaximumItemAge(maxage);
    ts5 = new TimeSeries("5min " + lavetext);
    ts5.setMaximumItemAge(maxage);
    ts15 = new TimeSeries("15min " + lavetext);
    ts15.setMaximumItemAge(maxage);

    updateAccessory();
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ts1);
    dataset.addSeries(ts5);
    dataset.addSeries(ts15);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"),
            KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false);

    XYPlot xyplot = chart.getXYPlot();

    NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT"));
    loadaxis.setAutoRange(true);
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

    DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME"));
    daxis.setAutoRange(true);
    daxis.setFixedAutoRange(maxage);
    xyplot.setDomainAxis(daxis);

    addWindowListener(new winExit());
    setContentPane(new ChartPanel(chart));

    JMenuBar jm = new JMenuBar();
    JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT"));
    jme.setMnemonic(KeyEvent.VK_F);
    exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X);
    exitItem.addActionListener(this);
    jme.add(exitItem);
    jm.add(jme);

    setJMenuBar(jm);

    pack();
    setVisible(true);
    Timer timer = new Timer(5000, this);
    timer.start();
}

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

/**
 * A demonstration application showing a high-low-open-close chart using a
 * segmented or non-segmented axis./* www  . j a  va 2 s .  c  om*/
 *
 * @param title  the frame title.
 * @param useSegmentedAxis use a segmented axis for this demo?
 * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday
 */
public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) {

    super(title);

    System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")");

    // create a Calendar object with today's date at midnight
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // create a timeline for the demo
    SegmentedTimeline timeline = null;
    switch (timelineType) {
    case 1:
        timeline = SegmentedTimeline.newMondayThroughFridayTimeline();
        break;

    case 2:
        timeline = SegmentedTimeline.newFifteenMinuteTimeline();

        final Calendar cal2 = (Calendar) cal.clone();
        cal2.add(Calendar.YEAR, 1);

        // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as
        // exceptions of the intraday timeline
        timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime());
        break;

    default:
        System.out.println("Invalid timelineType.");
        System.exit(1);
    }

    // create a data set that has data for trading days (Monday through Friday).
    final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline,
            cal.getTime());

    final JFreeChart chart;
    if (useSegmentedAxis) {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true);
    } else {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true);
    }

    final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setAutoRange(true);
    final TickUnits units = new TickUnits();
    units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    axis.setStandardTickUnits(units);

    final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    vaxis.setAutoRangeIncludesZero(false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    setContentPane(chartPanel);

}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChart.java

/**
 * Set up the X and Y axes./*from ww  w.  ja  v  a  2s  . c  o  m*/
 */
public void setAxes() {
    XYPlot xyplot = chart.getXYPlot();

    String ylabel = showdelta ? KstatResources.getString("CHART.RATE")
            : KstatResources.getString("CHART.VALUE");
    NumberAxis loadaxis = new NumberAxis(ylabel);
    loadaxis.setAutoRange(true);
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

    DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME"));
    daxis.setAutoRange(true);
    // let a sequnce show its full date range
    if (!(jkstat instanceof SequencedJKstat)) {
        daxis.setFixedAutoRange(maxage);
    }
    xyplot.setDomainAxis(daxis);
}

From source file:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);
    dateAxis.setLowerMargin(0);/*from w w  w  . j  a v a2 s.  c  om*/
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

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

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:net.sf.profiler4j.console.MemoryPlotPanel.java

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

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

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);
    dateAxis.setLowerMargin(0);// www .j a  v a 2 s  .  co m
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

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

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}