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

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

Introduction

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

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

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

/**
 * Creates a chart./*from w w w.  ja  v a 2  s  .  co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 6", "Date", "Value", dataset,
            true, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRangeMinimumSize(1.0);
    return chart;

}

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

/**
 * Creates a new chart./*w w  w . j  a v a  2 s .  c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The dataset.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 3", "Time", "Value", dataset,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM-yyyy")));
    axis.setVerticalTickLabels(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer.setSeriesShapesFilled(1, Boolean.FALSE);

    return chart;
}

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

/**
 * A demonstration application showing a scatter plot.
 * /*ww w . jav  a 2  s.  c  om*/
 * @param title
 *           the frame title.
 */
public ScatterPlotDemo(final String title) {

    super(title);
    final XYDataset data = new SampleXYDataset2();
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    final Legend legend = chart.getLegend();
    if (legend instanceof StandardLegend) {
        final StandardLegend sl = (StandardLegend) legend;
        sl.setDisplaySeriesShapes(true);
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalZoom(true);
    chartPanel.setHorizontalZoom(true);
    setContentPane(chartPanel);

}

From source file:DynamiskDemo2.java

/**
 * Creates a sample chart./*w w  w . ja v  a  2s  .  c o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createXYLineChart("Dynamic Data Demo", "Time", "Value", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(-0.5, 1.5);
    return result;
}

From source file:edu.emory.library.tast.database.graphs.GraphTypeXY.java

public JFreeChart createChart(Object[] data) {

    CategoryTableXYDataset dataset = new CategoryTableXYDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(),
            TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true,
            false);//ww  w . j a v  a 2  s .  c o m

    Format formatter = getSelectedIndependentVariable().getFormat();

    XYPlot plot = chart.getXYPlot();
    if (formatter != null)
        ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter);

    chart.setBackgroundPaint(Color.white);

    List allDataSeries = getDataSeries();
    for (int j = 0; j < allDataSeries.size(); j++) {
        DataSeries dataSearies = (DataSeries) allDataSeries.get(j);
        String dataSeriesLabel = dataSearies.formatForDisplay();
        for (int i = 0; i < data.length; i++) {
            Object[] row = (Object[]) data[i];
            Number x = (Number) row[0];
            Number y = (Number) row[j + 1];
            if (x != null && y != null)
                dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel);
        }
    }

    LegendItemCollection legendItems = chart.getPlot().getLegendItems();
    for (int i = 0; i < legendItems.getItemCount(); i++) {
        LegendItem legendItem = legendItems.get(i);
        DataSeries dataSearies = (DataSeries) allDataSeries.get(i);
        if (legendItem.getFillPaint() instanceof Color) {
            dataSearies.setColor(((Color) legendItem.getFillPaint()));
        }
    }

    return chart;

}

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

/**
 * Creates a sample chart.//from www. j  a  v a 2 s  .  c om
 * 
 * @return a sample chart.
 */
private JFreeChart createChart() {
    final XYDataset direction = createDirectionDataset(600);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to display directions...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    final TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(180.0, new CompassFormat()));
    units.add(new NumberTickUnit(90.0, new CompassFormat()));
    units.add(new NumberTickUnit(45.0, new CompassFormat()));
    units.add(new NumberTickUnit(22.5, new CompassFormat()));
    rangeAxis.setStandardTickUnits(units);

    // add the wind force with a secondary dataset/renderer/axis
    plot.setRangeAxis(rangeAxis);
    final XYItemRenderer renderer2 = new XYAreaRenderer();
    final ValueAxis axis2 = new NumberAxis("Force");
    axis2.setRange(0.0, 12.0);
    renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128));
    plot.setDataset(1, createForceDataset(600));
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);

    return chart;
}

From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java

/**
 * Creates the chart//from   w ww .j  a  va  2 s  .c o  m
 */
private void createChart() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            "Period", // x axis label
            "Discounted Cash", // y axis label
            null, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setChart(chart);
    setMouseZoomable(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0));
    renderer.setUseFillPaint(true);

    // the x=0 line
    renderer.setSeriesPaint(0, Color.GRAY);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesVisibleInLegend(0, new Boolean(false));

    plot.setRenderer(renderer);
}

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

/**
 * Creates a chart./*from   w  w w. j  a  va 2s  .  c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", dataset,
            PlotOrientation.HORIZONTAL, true, // legend
            false, // tooltips
            false // urls
    );
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    return chart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);/*from   w w  w .  ja va2 s  . co m*/
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:it.unibo.alchemist.boundary.gui.asmc.SimplePlot.java

@Override
public void batchDone(final double[][] values, final double lower, final double upper, final int sampleSize) {
    this.removeAll();
    final YIntervalSeries series = new YIntervalSeries("Probability of condition satisfaction vs. time");
    for (final double[] value : values) {
        series.add(value[0], value[1], value[2], value[TRE]);
    }//w  w  w  .j av a  2  s .  c om
    final YIntervalSeriesCollection data = new YIntervalSeriesCollection();
    data.addSeries(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("", "X", "Y", data, PlotOrientation.VERTICAL, true,
            true, false);
    XYItemRenderer renderer;
    switch (currentRenderer) {
    case 1:
        renderer = new YIntervalRenderer();
        break;
    case 0:
    default:
        renderer = new DeviationRenderer(true, false);
    }
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.getDomainAxis().setLowerBound(lower);
    plot.getDomainAxis().setUpperBound(upper);
    plot.getRangeAxis().setUpperBound(1.0);
    plot.getRangeAxis().setLowerBound(0.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(DIMENSION);
    this.setLayout(new BorderLayout());
    this.add(chartPanel, BorderLayout.NORTH);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            chartPanel.getRootPane().validate();
        }
    });
}