Example usage for org.jfree.chart.util RelativeDateFormat RelativeDateFormat

List of usage examples for org.jfree.chart.util RelativeDateFormat RelativeDateFormat

Introduction

In this page you can find the example usage for org.jfree.chart.util RelativeDateFormat RelativeDateFormat.

Prototype

public RelativeDateFormat(long baseMillis) 

Source Link

Document

Creates a new instance.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Exercise Chart", "Elapsed Time",
            "Beats Per Minute", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }//from  w  ww  . j  a v  a 2 s  .c om
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    Minute minute = new Minute(0, 9, 1, 10, 2006);
    RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
    relativedateformat.setSecondFormatter(new DecimalFormat("00"));
    dateaxis.setDateFormatOverride(relativedateformat);
    return jfreechart;
}

From source file:de.xirp.ui.widgets.panels.LiveChartComposite.java

/**
 * Initializes the listeners./*from   w w  w. j  av  a 2 s  .  c  o m*/
 */
private void init() {
    addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            pool.removeDatapoolReceiveListener(listener);
        }

    });

    initDatapool();
    keysList = ProfileManager.getSensorDatapoolKeys(robotName);
    dataset = new TimeSeriesCollection();
    chart = createChart(dataset);

    SWTUtil.setGridLayout(this, 1, true);

    final XToolBar toolBar = new XToolBar(this, SWT.FLAT);
    SWTUtil.setGridData(toolBar, true, false, SWT.FILL, SWT.BEGINNING, 1, 1);

    keysMenu = new Menu(getShell(), SWT.POP_UP);

    keys = new XToolItem(toolBar, SWT.DROP_DOWN | SWT.FLAT);
    keys.setImage(ImageManager.getSystemImage(SystemImage.ADD));
    keys.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.startOrStop"); //$NON-NLS-1$
    keys.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            Rectangle rect = keys.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = toolBar.toDisplay(pt);
            keysMenu.setLocation(pt.x, pt.y);
            keysMenu.setVisible(true);
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL);

    XToolItem timeMode = new XToolItem(toolBar, SWT.CHECK | SWT.FLAT);
    timeMode.setImage(ImageManager.getSystemImage(SystemImage.ABSOLUTE));
    timeMode.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.switchTimeMode"); //$NON-NLS-1$
    timeMode.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            XToolItem itm = (XToolItem) e.widget;
            if (itm.getSelection()) {
                if (chart != null && start != null) {
                    XYPlot plot = chart.getXYPlot();
                    DateAxis axis = new DateAxis(I18n.getString("LiveChartComposite.text.relativeTime")); //$NON-NLS-1$
                    RelativeDateFormat rdf = new RelativeDateFormat(start);
                    axis.setDateFormatOverride(rdf);
                    plot.setDomainAxis(axis);
                    ValueAxis vaxis = plot.getDomainAxis();
                    vaxis.setAutoRange(true);
                    vaxis.setFixedAutoRange(60000);
                }
                itm.setImage(ImageManager.getSystemImage(SystemImage.RELATIVE));
            } else {
                if (chart != null) {
                    XYPlot plot = chart.getXYPlot();
                    plot.setDomainAxis(new DateAxis(I18n.getString("LiveChartComposite.text.absoluteTime"))); //$NON-NLS-1$
                    ValueAxis vaxis = plot.getDomainAxis();
                    vaxis.setAutoRange(true);
                    vaxis.setFixedAutoRange(60000);
                }
                itm.setImage(ImageManager.getSystemImage(SystemImage.ABSOLUTE));
            }
        }

    });

    new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL);

    startStop = new XToolItem(toolBar, SWT.CHECK | SWT.FLAT);
    startStop.setImage(ImageManager.getSystemImage(SystemImage.START));
    startStop.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.startOrStop"); //$NON-NLS-1$
    startStop.setEnabled(false);
    startStop.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            final XToolItem itm = (XToolItem) e.widget;
            final boolean enabled = itm.getSelection();
            keys.setEnabled(!enabled);
            if (enabled) {
                setPlottingEnabled(enabled);
                itm.setImage(ImageManager.getSystemImage(SystemImage.STOP));
            } else {
                SWTUtil.showBusyWhile(getShell(), new Runnable() {

                    public void run() {
                        setPlottingEnabled(enabled);
                        itm.setImage(ImageManager.getSystemImage(SystemImage.START));
                    }
                });
            }
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL);

    //      XToolItem thresholdItm = new XToolItem(toolBar, SWT.SEPARATOR);
    //      thresholdItm.setWidth(75);
    //
    //      //TODO: Double spinner, remove of old thres line
    //      XSpinner threshold = new XSpinner(toolBar, SWT.BORDER);
    //      threshold.setIncrement(1);
    //      threshold.setMaximum(1);
    //      threshold.setMaximum(Integer.MAX_VALUE);
    //      threshold.setEnabled(false);
    //      threshold.addSelectionListener(new SelectionAdapter( ) {
    //
    //         /* (non-Javadoc)
    //          * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
    //          */
    //         @Override
    //         public void widgetSelected(SelectionEvent e) {
    //            XSpinner spn = (XSpinner) e.widget;
    //            double value = spn.getSelection( );
    //            if (chart != null && value > 0) {
    //               XYPlot plot = (XYPlot) chart.getPlot( );
    //               Marker marker = new ValueMarker(value);
    //               marker.setPaint(Color.orange);
    //               marker.setAlpha(0.8f);
    //               plot.addRangeMarker(marker);
    //            }
    //         }
    //
    //      });
    //      thresholdItm.setControl(threshold);

    initKeysMenu();

    cc = new XChartComposite(this, SWT.NONE, null, false, robotName);
    SWTUtil.setGridData(cc, false, true, SWT.FILL, SWT.FILL, 1, 1);
}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

private static CombinedDomainXYPlot createRelativeTimeSeriesPlot() {
    DateAxis timeAxis = new DateAxis("Time");
    RelativeDateFormat relativeDateFormat = new RelativeDateFormat(referenceDate);
    relativeDateFormat.setSecondFormatter(new DecimalFormat("0"));
    relativeDateFormat.setShowZeroHours(false);
    timeAxis.setDateFormatOverride(relativeDateFormat);
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis);
    return plot;/*w  ww.  java  2s. co m*/
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Sets some values on the given//from ww  w. j  av  a  2 s  . c om
 * {@link org.jfree.chart.plot.XYPlot} corresponding to some
 * options of the {@link de.xirp.chart.ChartOptions}
 * field. <br>
 * <br>
 * If <code>options.is(OptionName.SHOW_THRESHOLD)</code> is
 * <code>true</code> a threshold line is painted to the chart
 * using the <code>threshold</code> field. <br>
 * <br>
 * If <code>options.is(OptionName.USE_RELATIVE)</code> is
 * <code>true</code> the date axis of the plot gets a title
 * indicating that relative values are used. If the flag is
 * <code>false</code> the plot gets a title indicating that
 * absolute values are used.
 * 
 * @param plot
 *            The plot to alter.
 * @param start
 *            The start time.
 * @see de.xirp.chart.ChartOptions
 * @see org.jfree.chart.plot.XYPlot
 */
private static void setXYPlot(XYPlot plot, Date start) {
    plot.setNoDataMessage(NO_DATA_AVAILABLE);

    if (options.is(OptionName.SHOW_THRESHOLD)) {
        Marker marker = new ValueMarker(threshold);
        marker.setPaint(Color.orange);
        marker.setAlpha(0.8f);
        plot.addRangeMarker(marker);
    }

    if (options.is(OptionName.USE_RELATIVE)) {
        DateAxis axis = new DateAxis(I18n.getString("ChartManager.text.relativeTime")); //$NON-NLS-1$
        RelativeDateFormat rdf = new RelativeDateFormat(start);
        axis.setDateFormatOverride(rdf);
        plot.setDomainAxis(axis);
    } else {
        plot.setDomainAxis(new DateAxis(I18n.getString("ChartManager.text.absoluteTime"))); //$NON-NLS-1$
    }
}