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

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

Introduction

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

Prototype

public void setDomainAxis(ValueAxis axis) 

Source Link

Document

Sets the domain axis for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java

private void buildLegendChart(int nbValues) {
    this.legendValues = new int[nbValues + 1];
    this.legendValues[0] = 0;
    int offset = 255 / nbValues;
    int step = offset;

    if (this.scaleMode == Chart.Scale.LOGARITHMIC) {
        double logStep = (Math.log(this.maxValue) / Math.log(2)) / nbValues;
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (int) Math.pow(2, logStep * i);
        }//w w  w . j a  v  a 2  s  . co  m
    } else { // Linear scale mode
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (step * this.maxValue) / 255;
            step += offset;
        }
    }

    final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createLegendDataSet());

    final JFreeChart chart = ChartFactory.createBubbleChart("", "", "", dataset, PlotOrientation.VERTICAL, true,
            true, false);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE));
    chart.removeLegend();

    // Perform customizations starts here ...
    final XYPlot plot1 = chart.getXYPlot();

    plot1.setDomainGridlinesVisible(false);
    plot1.setRangeGridlinesVisible(false);
    plot1.setForegroundAlpha(0.5f);
    plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel()));
    plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel()));

    // Custumize the domain axis ( x )
    final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-1, 1);
    domainAxis.setVisible(false);

    // Custumize the range axis ( y )
    final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
    rangeAxis.setTickUnit(new CustomTickUnit(rangeAxis.getTickUnit().getSize()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(-1, this.legendValues.length);
    rangeAxis.setTickLabelsVisible(true);
    rangeAxis.setTickMarkInsideLength(4);

    // Create custom renderer
    StandardXYItemRenderer ren = new CustomRenderer(true);
    ren.setSeriesItemLabelPaint(0, Color.BLUE);
    plot1.setRenderer(ren);
    plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);

    this.legendChart = chart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", 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);
        xylineandshaperenderer.setBaseItemLabelsVisible(true);
    }//from  w  ww.  j  a v a  2s. c o  m
    PeriodAxis periodaxis = new PeriodAxis("Date");
    periodaxis.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
    periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class);
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[3];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"));
    aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class,
            new SimpleDateFormat("MMM"), new RectangleInsets(2D, 2D, 2D, 2D), new Font("SansSerif", 1, 10),
            Color.blue, false, new BasicStroke(0.0F), Color.lightGray);
    aperiodaxislabelinfo[2] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class,
            new SimpleDateFormat("yyyy"));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);
    return jfreechart;
}

From source file:playground.dgrether.events.handlers.DgGeoFilteredLegHistogram.java

private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
        onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
        double hour = i * this.binSizeSeconds / 60.0 / 60.0;
        departuresSerie.add(hour, modeData.countsDep[i]);
        arrivalsSerie.add(hour, modeData.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }//from w w w.  j  a v a 2 s. com

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration, "time", "# vehicles", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

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

From source file:edu.ucla.stat.SOCR.chart.demo.DifferenceChartDemo1.java

/**
 * Creates a chart.//from   w w  w . j  av a  2  s .  co m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, rangeLabel, dataset,
            !legendPanelOn, // legend
            true, // tool tips
            false // URLs
    );
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    ValueAxis domainAxis = new DateAxis("Time");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    //setXSummary(dataset) X is time;          
    return chart;

}

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

/**
 * Set up the X and Y axes.//from  w ww .  j a v a 2 s  .  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:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java

/**
 * The resulting chart consists a TimeSeries for each FeatureOfInterest contained in the
 * observationCollection./*from  www . j  a v a 2 s  . c o  m*/
 * 
 * @param foiIdArray
 *        the IDs of the FeaturesOfInterest whose Observations shall be rendered
 * @param observationCollection
 * @return
 */
protected XYPlot drawChart4FOI(String foiID, Map<ITimePosition, ObservedValueTuple> timeMap) {

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries timeSeries = new TimeSeries(foiID, Second.class);

    for (ITimePosition timePos : timeMap.keySet()) {
        Number value = (Number) timeMap.get(timePos).getValue(0);
        timeSeries.add(
                new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(),
                        timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()),
                value);
    }

    dataset.addSeries(timeSeries);
    dataset.setDomainIsPointsInTime(true);

    //
    // create Plot:
    //

    XYPlot plot = new XYPlot();

    plot.setDataset(dataset);
    plot.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(renderer);

    DateAxis dateAxis = new DateAxis();
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    dateAxis.setTickMarksVisible(true);
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd'.'MM'.'"));
    plot.setDomainAxis(dateAxis);

    plot.setRangeAxis(new NumberAxis());

    return plot;
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
  * Build a JPanel with plotType of a DesmoJ time-series dataset.
 * When allowMultipleValues is set, multiple range values of a time value are allowed.
 * In the opposite Case only the last range value of a time value is accepted.
 * In the case ts.getShowTimeSpansInReport() the data values are interpreted as
 * a timespan in a appropriate time unit. 
  * @param ts               DesmoJ time-series dataset
  * @param plotType          possible Values: 
  *                         Plotter.TimeSeries_ScatterPlot, 
  *                         Plotter.TimeSeries_StepChart
  *                         Plotter.TimeSeries_LinePlot
 * @param allowMultipleValues//from   w w w  .j  a  va2  s.c om
 * @return
 */
private JPanel getTimeSeriesPanel(TimeSeries ts, int plotType, boolean allowMultipleValues) {
    JFreeChart chart;
    TimeSeriesDataSetAdapter dataset = new TimeSeriesDataSetAdapter(ts, allowMultipleValues);
    switch (plotType) {
    case Plotter.TimeSeries_LineChart:
        chart = ChartFactory.createXYLineChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_ScatterPlot:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_StepChart:
        chart = ChartFactory.createXYStepChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    default:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    }
    if (ts.getDescription() != null)
        chart.setTitle(ts.getDescription());

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    if (ts.getShowTimeSpansInReport() && !dataset.isValid())
        xyplot.setNoDataMessage("NO VALID TIMESPANS");
    xyplot.setDomainZeroBaselineVisible(false);
    xyplot.setRangeZeroBaselineVisible(false);

    DateAxis dateAxis = new DateAxis();
    xyplot.setDomainAxis(dateAxis);
    this.configureDomainAxis(dateAxis);

    String numberLabel;
    if (!dataset.isValid())
        numberLabel = "Unit: invalid";
    else if (ts.getShowTimeSpansInReport())
        numberLabel = "Unit: timespan [" + dataset.getRangeTimeUnit().name() + "]";
    else if (ts.getUnit() != null)
        numberLabel = "Unit: [" + ts.getUnit() + "]";
    else
        numberLabel = "Unit: unknown";
    NumberAxis numberAxis = new NumberAxis();
    xyplot.setRangeAxis(numberAxis);
    this.configureRangeAxis(numberAxis, numberLabel);

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
    xylineandshaperenderer.setUseOutlinePaint(true);

    ChartPanel panel = new ChartPanel(chart);
    panel.setVerticalAxisTrace(false);
    panel.setHorizontalAxisTrace(false);
    panel.setPopupMenu(null);
    panel.setDomainZoomable(false);
    panel.setRangeZoomable(false);

    return panel;
}

From source file:ec.ui.view.StabilityView.java

private void showDetail(Graphs g) {
    XYPlot plot = detailChart.getXYPlot();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelPaint(Color.GRAY);
    plot.setRangeAxis(yAxis);//from  w w w  . j  av  a 2s . co  m

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelPaint(Color.GRAY);
    xAxis.setTickUnit(new NumberTickUnit(1));
    xAxis.setRange(-0.5, ((double) g.getMaxElements()) - 0.5);
    plot.setDomainAxis(xAxis);

    plot.setDataset(MEAN_INDEX, new BasicXYDataset(Collections.singletonList(g.S1_)));
    plot.setDataset(POINTS_INDEX, new BasicXYDataset(Collections.singletonList(g.S2_)));
    plot.setDataset(SMOOTH_INDEX, new BasicXYDataset(Collections.singletonList(g.S3_)));

    rescaleAxis((NumberAxis) plot.getRangeAxis());

    detailChart.setTitle(g.label_);
    panel.setChart(detailChart);
    panel.setToolTipText("Right click to show complete data");
    onColorSchemeChange();
}

From source file:uk.co.petertribble.jangle.SnmpChart.java

private void setAxes() {
    XYPlot xyplot = chart.getXYPlot();

    String ylabel = showdelta ? SnmpResources.getString("CHART.RATE") : SnmpResources.getString("CHART.VALUE");
    NumberAxis loadaxis = new NumberAxis(ylabel);
    loadaxis.setAutoRange(true);//from w w w  .  ja va 2  s  .  co  m
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

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

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

/**
 * Initializes the listeners./*from  www  . j a v  a2 s.  c om*/
 */
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);
}